Skip to content

Tiered discount banner in WordPress

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.

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

bandeau-soldes-remise-paliers.php
<?php
/**
 * Plugin Name: Forge, Bandeau de remise par paliers
 * Description: Une carte de soldes qui affiche la remise croissante selon le montant du panier (-10 % dès 50 €, -15 % dès 100 €…) avec une barre de progression vers le palier suivant. Ajoute la composition « Bandeau de remise par paliers » à 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-bandeau-soldes-remise-paliers
 *
pattern.html
<!-- wp:html -->
<section class="brp" data-brp data-brp-amount="38.50" aria-labelledby="brp-titre">
        <div class="brp-head">
          <p class="brp-badge">Soldes d’hiver · jusqu’au 31 janvier</p>
          <h2 class="brp-title" id="brp-titre">Plus le panier grandit, plus la remise grimpe</h2>
        </div>
        <ol class="brp-tiers" aria-label="Paliers de remise">
            <li class="brp-tier" data-brp-tier="50" data-brp-rate="10">
              <span class="brp-rate">-10 %</span>
              <span class="brp-from">dès 50 €</span>
              <span class="brp-state" data-brp-state>À venir</span>
              <svg class="brp-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12.5 4.5 4L19 7"/></svg>
script.js
(() => {
  if (!document.querySelector(".brp")) return;
  document.querySelectorAll("[data-brp]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const offs = [];
    const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });
    const pct = (rate) => `-${rate}\u00a0%`;
    const tiers = [...root.querySelectorAll("[data-brp-tier]")]
      .map((el) => ({ el, floor: Number(el.dataset.brpTier), rate: Number(el.dataset.brpRate) }))
      .sort((a, b) => a.floor - b.floor);
    const max = tiers[tiers.length - 1].floor;
    const out = (name) => root.querySelector(`[data-brp-${name}]`);
style.css
:root {
  --brp-card: #ffffff;
  --brp-text: #2b1613;
  --brp-muted: #6b4d47;
  --brp-line: #f0dcd7;
  --brp-soft: #fff6f3;
  --brp-hit: #fdecea;
  --brp-track: #f6e3de;
  --brp-fill: #d92d20;
  --brp-accent: #b42318;
  --demo-bandeau-soldes-remise-paliers-bg: #f8efec;
  --demo-bandeau-soldes-remise-paliers-text: #2b1613;

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 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
  • 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