Skip to content

Product page in WordPress

A complete product page: product views, colors and sizes as radio buttons, a quantity selector and an announced add-to-cart.

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

fiche-produit.php
<?php
/**
 * Plugin Name: Forge, Fiche produit
 * Description: Une fiche produit complète : vues du produit, couleurs et contenances en boutons radio, sélecteur de quantité et ajout au panier annoncé. Ajoute la composition « Fiche produit » à 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-fiche-produit
 *
pattern.html
<!-- wp:html -->
<section class="fp" aria-labelledby="fp-title" data-product>
        <div class="fp__media">
          <div class="fp__photo fp__visual" role="img" aria-label="Mug Sauge, vue de face" data-product-photo style="--angle: 160deg"></div>
          <div class="fp__thumbs" role="group" aria-label="Vues du produit" data-enhanced hidden>
            <button type="button" class="fp__thumb" aria-label="Vue de face" aria-pressed="true" data-view="vue de face" data-angle="160deg" style="--angle: 160deg"><span class="fp__visual"></span></button>
            <button type="button" class="fp__thumb" aria-label="Vue de profil" aria-pressed="false" data-view="vue de profil" data-angle="100deg" style="--angle: 100deg"><span class="fp__visual"></span></button>
            <button type="button" class="fp__thumb" aria-label="Détail de l&#x27;émail" aria-pressed="false" data-view="détail de l&#x27;émail" data-angle="220deg" style="--angle: 220deg"><span class="fp__visual"></span></button>
          </div>
        </div>
        <div class="fp__info">
          <p class="fp__brand">Atelier Terre &amp; Feu</p>
script.js
(() => {
  if (!document.querySelector(".fp")) return;
  document.querySelectorAll("[data-product]").forEach((root) => {
    const form = root.querySelector("form");
    const photo = root.querySelector("[data-product-photo]");
    const views = [...root.querySelectorAll("[data-view]")];
    const quantity = form.elements.quantite;
    const status = root.querySelector("[data-product-status]");
    const euros = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });
    let view = views[0];

    function render() {
style.css
:root {
  --fp-text: #2a1f14;
  --fp-muted: #6b5848;
  --fp-field: #ffffff;
  --fp-line: #e6dccf;
  --fp-accent: #3f2a1a;
  --fp-accent-hover: #2a1b10;
  --fp-accent-text: #ffffff;
  --fp-success: #3d6b35;
  --fp-ring: #3f2a1a;
  --demo-fiche-produit-bg: #faf7f2;
  --demo-fiche-produit-text: #2a1f14;

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