Skip to content

Shipping options in WordPress

Radio cards to pick a shipping method, with each option's delay and price, and an order total that updates instantly.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

choix-livraison.php
<?php
/**
 * Plugin Name: Forge, Choix de livraison
 * Description: Des cartes radio pour choisir le mode de livraison, avec délai et prix de chaque option, et un total de commande mis à jour aussitôt. Ajoute la composition « Choix de livraison » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-choix-livraison
 *
pattern.html
<!-- wp:html -->
<form class="ship" action="#paiement" data-shipping data-subtotal="5400">
        <fieldset>
          <legend>Mode de livraison</legend>
          <div class="ship__list">
            <label class="ship__card">
              <input type="radio" name="livraison" value="retrait" data-cost="0">
              <span class="ship__text"><strong>Retrait en boutique</strong><span class="ship__delay">Prêt sous 2 h, 12 rue Mercière à Lyon</span></span>
              <span class="ship__price">Gratuit</span>
            </label>
            <label class="ship__card">
              <input type="radio" name="livraison" value="relais" data-cost="390" checked>
script.js
(() => {
  if (!document.querySelector(".ship")) return;
  document.querySelectorAll("[data-shipping]").forEach((form) => {
    const euros = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });
    const subtotal = Number(form.dataset.subtotal);

    function update() {
      const cost = Number(form.querySelector('[name="livraison"]:checked').dataset.cost);
      form.querySelector("[data-shipping-cost]").textContent = cost === 0 ? "Gratuit" : euros.format(cost / 100);
      form.querySelector("[data-shipping-total]").textContent = euros.format((subtotal + cost) / 100);
    }
style.css
:root {
  --ship-text: #2b0d0f;
  --ship-muted: #6e4a4d;
  --ship-card: #ffffff;
  --ship-line: #f0d6d8;
  --ship-accent: #b4232f;
  --ship-accent-hover: #981b26;
  --ship-accent-text: #ffffff;
  --ship-ring: #7f1d1d;
  --demo-choix-livraison-bg: #fdf6f6;
  --demo-choix-livraison-text: #2b0d0f;
}

Free component: copy it freely, including for commercial projects.

E-commerce components in WordPress
  • A limited-time offer bar: countdown to a fixed date, one-click copyable promo code and a fallback message once the offer is over.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A sales card showing the discount that grows with the cart amount (-10% from €50, -15% from €100…) with a progress bar towards the next tier.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A Christmas gift guide filtered by budget and theme, with the number of ideas announced and an empty state offering to show everything again.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • The last order dates for delivery before Christmas, per shipping method, with the days left worked out from the visitor’s date.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A cart that shows live how much is left to add for free shipping, with a progress bar and recalculated totals.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A colour and size picker for a product page: the visual, price and stock follow the choice, and sold-out sizes are disabled.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component