Product comparison in WordPress
Tick two or three products to compare them side by side in an accessible table, with no reload.
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
The code in WordPress
<?php
/**
* Plugin Name: Forge, Comparateur de produits
* Description: Cochez deux ou trois produits pour les comparer côte à côte dans un tableau accessible, sans rechargement. Ajoute la composition « Comparateur de produits » à 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-comparateur-produits
*<!-- wp:html -->
<section class="cpp-comparateur-produits" data-cpp data-cpp-max="3" aria-labelledby="cpp-titre">
<h2 class="cpp-title" id="cpp-titre">Nos vélos électriques</h2>
<ul class="cpp-grid">
<li class="cpp-card">
<h3 class="cpp-name">Citadin 300</h3>
<p class="cpp-price">1 490 €</p>
<label class="cpp-check"><input class="cpp-input" type="checkbox" value="ville" data-cpp-pick> Comparer</label>
</li>
<li class="cpp-card">
<h3 class="cpp-name">Randonneur 500</h3>
<p class="cpp-price">2 190 €</p>(() => {
if (!document.querySelector(".cpp-comparateur-produits")) return;
document.querySelectorAll("[data-cpp]").forEach((root) => {
const on = (el, type, fn) => el.addEventListener(type, fn);
const max = Number(root.getAttribute("data-cpp-max"));
const picks = [...root.querySelectorAll("[data-cpp-pick]")];
const hint = root.querySelector("[data-cpp-hint]");
const table = root.querySelector("[data-cpp-table]");
const update = () => {
const chosen = picks.filter((p) => p.checked).map((p) => p.value);
picks.forEach((p) => {:root {
--cpp-comparateur-produits-card: #ffffff;
--cpp-comparateur-produits-text: #10231c;
--cpp-comparateur-produits-muted: #46594f;
--cpp-comparateur-produits-line: #d6e2db;
--cpp-comparateur-produits-soft: #f1f7f3;
--cpp-comparateur-produits-accent: #047857;
--demo-comparateur-produits-bg: #e8f0eb;
--demo-comparateur-produits-text: #10231c;
}
@media (prefers-color-scheme: dark) {Free component: copy it freely, including for commercial projects.
Other e-commerce components in WordPress
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

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

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

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

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

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