Skip to content

Wishlist in WordPress

A wishlist for an online shop: add from product cards, a summary with total and removal, remembered in the browser.

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

liste-envies.php
<?php
/**
 * Plugin Name: Forge, Liste d’envies
 * Description: Une liste d’envies pour boutique en ligne : ajout depuis les cartes produit, récapitulatif avec total et retrait, mémorisée dans le navigateur. Ajoute la composition « Liste d’envies » à 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-liste-envies
 *
pattern.html
<!-- wp:html -->
<section data-lev-remove-class="lev-remove" class="lev" data-lev aria-labelledby="lev-titre">
        <h2 class="lev-title" id="lev-titre">Idées cadeaux</h2>
        <ul class="lev-grid">
          <li class="lev-card" data-lev-item="theiere" data-name="Théière en fonte, 0,8 l" data-price="48">
            <span class="lev-name">Théière en fonte, 0,8 l</span>
            <span class="lev-price">48 €</span>
            <button class="lev-add" type="button" aria-pressed="false" data-lev-toggle>Ajouter à ma liste<span class="lev-sr"> : Théière en fonte, 0,8 l</span></button>
          </li>
          <li class="lev-card" data-lev-item="bol" data-name="Bols en grès émaillé, lot de 2" data-price="32">
            <span class="lev-name">Bols en grès émaillé, lot de 2</span>
            <span class="lev-price">32 €</span>
script.js
(() => {
  if (!document.querySelector(".lev")) return;
  document.querySelectorAll("[data-lev]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const KEY = "forge-lev-envies";
    const cards = [...root.querySelectorAll("[data-lev-item]")];
    const list = root.querySelector("[data-lev-list]");
    const status = root.querySelector("[data-lev-status]");
    const removeClass = root.getAttribute("data-lev-remove-class") ?? "";
    let saved = [];
    try {
      saved = JSON.parse(localStorage.getItem(KEY) ?? "[]");
style.css
:root {
  --lev-liste-envies-card: #ffffff;
  --lev-liste-envies-text: #2a1f17;
  --lev-liste-envies-muted: #5f5145;
  --lev-liste-envies-line: #d9cfc4;
  --lev-liste-envies-panel: #faf6f1;
  --lev-liste-envies-accent: #8a3b12;
  --lev-liste-envies-accent-text: #ffffff;
  --demo-liste-envies-bg: #f1ebe4;
  --demo-liste-envies-text: #2a1f17;
}

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