Skip to content

Christmas delivery deadlines in WordPress

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

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

date-limite-livraison-noel.php
<?php
/**
 * Plugin Name: Forge, Date limite de livraison avant Noël
 * Description: Les dates limites de commande pour être livré avant Noël, par mode de livraison, avec le nombre de jours restants calculé d’après la date du visiteur. Ajoute la composition « Date limite de livraison avant Noël » à 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-date-limite-livraison-noel
 *
pattern.html
<!-- wp:html -->
<section class="dld" data-dld aria-labelledby="dld-titre">
        <p class="dld-eyebrow">Maison Ferrand · épicerie fine</p>
        <h2 class="dld-title" id="dld-titre">Vos paniers garnis à temps pour Noël</h2>
        <p class="dld-summary" data-dld-summary>Chaque mode de livraison a sa date limite : commandez avant celle qui vous convient.</p>
        <ul class="dld-list">
          <li class="dld-row" data-dld-row data-dld-deadline="12-16T18:00" data-dld-mode="Point relais">
            <div class="dld-info">
              <h3 class="dld-name">Point relais</h3>
              <p class="dld-detail">Mondial Relay, 3 à 5 jours ouvrés</p>
            </div>
            <p class="dld-when">Commande avant le <time>16 décembre, 18 h</time></p>
script.js
(() => {
  if (!document.querySelector(".dld")) return;
  document.querySelectorAll("[data-dld]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const now = new Date();
    let year = now.getFullYear();
    // After Christmas, the countdown is for next year's.
    if (now > new Date(year, 11, 25, 23, 59)) year += 1;
    const day = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
    const hour = (d) => `${d.getHours()} h${d.getMinutes() ? String(d.getMinutes()).padStart(2, "0") : ""}`;
    const long = new Intl.DateTimeFormat("fr-FR", { weekday: "long", day: "numeric", month: "long" });
    let next = "";
style.css
:root {
  --dld-card: #ffffff;
  --dld-text: #2a1d1a;
  --dld-muted: #5c4d48;
  --dld-line: #eadfdb;
  --dld-accent: #9f1239;
  --dld-open-bg: #dcfce7;
  --dld-open-text: #14532d;
  --dld-soon-bg: #ffedd5;
  --dld-soon-text: #7c2d12;
  --dld-closed-bg: #e7e5e4;
  --dld-closed-text: #44403c;

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