Skip to content

Personalised gift card in WordPress

A gift card form: preset or custom amount, design, recipient, message and send date, with a live preview of the card.

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

carte-cadeau-personnalisee.php
<?php
/**
 * Plugin Name: Forge, Carte cadeau personnalisée
 * Description: Un formulaire de carte cadeau : montant prédéfini ou libre, motif, destinataire, message et date d'envoi, avec un aperçu de la carte mis à jour en direct. Ajoute la composition « Carte cadeau personnalisée » à 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-carte-cadeau-personnalisee
 *
pattern.html
<!-- wp:html -->
<section class="gcp" aria-labelledby="gcp-title" data-gcp>
        <div class="gcp__intro">
          <p class="gcp__eyebrow">Comptoir des Saveurs</p>
          <h2 id="gcp-title">Offrir une carte cadeau</h2>
          <p class="gcp__lead">Valable un an en boutique et sur notre site, elle est envoyée par e-mail au destinataire à la date de votre choix.</p>
        </div>
        <div class="gcp__layout">
          <form class="gcp__form" action="#panier" data-gcp-form>
            <fieldset>
              <legend>Montant</legend>
              <div class="gcp__options">
script.js
(() => {
  if (!document.querySelector(".gcp")) return;
  document.querySelectorAll("[data-gcp]").forEach((root) => {
    const form = root.querySelector("[data-gcp-form]");
    const f = form.elements;
    const card = root.querySelector("[data-gcp-card]");
    const custom = root.querySelector("[data-gcp-custom]");
    const status = root.querySelector("[data-gcp-status]");
    const out = (name) => root.querySelector(`[data-gcp-${name}]`);
    const euros = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });
    const round = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR", maximumFractionDigits: 0 });
    const longDate = new Intl.DateTimeFormat("fr-FR", { day: "numeric", month: "long", year: "numeric" });
style.css
:root {
  --gcp-text: #1f1a24;
  --gcp-muted: #5f5868;
  --gcp-field: #ffffff;
  --gcp-line: #ddd6e3;
  --gcp-accent: #6b21a8;
  --gcp-accent-hover: #581c87;
  --gcp-accent-text: #ffffff;
  --gcp-error: #b42318;
  --gcp-success: #166534;
  --gcp-ring: #6b21a8;
  --gcp-scheme: light;

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