Skip to content

Free shipping progress bar in WordPress

A cart that shows live how much is left to add for free shipping, with a progress bar and recalculated totals.

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

pattern.html
<!-- wp:html -->
<section class="slg" data-slg data-slg-threshold="45" data-slg-shipping="5.9" aria-labelledby="slg-titre">
        <h2 class="slg-title" id="slg-titre">Votre panier</h2>
        <div class="slg-goal">
          <p class="slg-msg" role="status" data-slg-msg>Plus que <strong>17,10 €</strong> pour profiter de la livraison offerte.</p>
          <div class="slg-track" role="progressbar" aria-label="Progression vers la livraison offerte" aria-valuemin="0" aria-valuemax="45" aria-valuenow="27.90" aria-valuetext="27,90 € sur 45,00 €" data-slg-track>
            <span class="slg-fill" style="transform: scaleX(0.620)" data-slg-fill></span>
          </div>
          <p class="slg-scale"><span>0 €</span><span>Livraison offerte dès 45 €</span></p>
        </div>
        <ul class="slg-list">
          <li class="slg-row" data-slg-item="14.9">
script.js
(() => {
  if (!document.querySelector(".slg")) return;
  document.querySelectorAll("[data-slg]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const threshold = Number(root.getAttribute("data-slg-threshold"));
    const shipping = Number(root.getAttribute("data-slg-shipping"));
    const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });
    const items = [...root.querySelectorAll("[data-slg-item]")];
    const out = (name) => root.querySelector(`[data-slg-${name}]`);

    const update = () => {
      const sub = items.reduce(
seuil-livraison-gratuite.php
<?php
/**
 * Plugin Name: Forge, Barre de livraison offerte
 * Description: Un panier qui montre en direct combien il reste à ajouter pour la livraison offerte, avec barre de progression et totaux recalculés. Ajoute la composition « Barre de livraison offerte » à 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-seuil-livraison-gratuite
 *
style.css
:root {
  --slg-card: #ffffff;
  --slg-text: #1f2a1d;
  --slg-muted: #52604d;
  --slg-line: #e3e8df;
  --slg-track: #edf1ea;
  --slg-fill: #4d7c0f;
  --slg-done: #15803d;
  --slg-goal: #f6f9f2;
  --slg-accent: #3f6212;
  --demo-seuil-livraison-gratuite-bg: #eef1ea;
  --demo-seuil-livraison-gratuite-text: #1f2a1d;

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 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
  • A wishlist for an online shop: add from product cards, a summary with total and removal, remembered in the browser.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component