Add a “New” badge to recent products

Published on: 6 October 2025. Last updated date: 6 October 2025

 

In e-commerce, new products naturally attract curiosity. A “New” badge helps to distinguish them effortlessly, boosting clicks and giving your store a fresh feel. The problem is that WooCommerce does not offer this basic feature. Fortunately, a small piece of well-placed code solves the problem without the need for unnecessary plugins.

This snippet checks the publication date of each product displayed in the WooCommerce store. It compares this date to the current date to determine whether the product is recent enough—in this case, less than 30 days old—to be considered “new.” If so, it inserts a small HTML block containing the “New” badge just before the product title in the display loop. The badge is styled in CSS to appear visibly (top left, with a bright color), and you can adjust the freshness duration or style as needed. In summary, the code hooks into a WooCommerce hook (woocommerce_before_shop_loop_item_title) to dynamically enrich each product page without modifying the core of the theme. Translated with DeepL.com (free version)

Result : a stylized CSS badge visible on products less than 30 days old.

1|Information

Before using this snippet, make sure you have installed the Code Snippets plugin (free) on your WordPress site. If not, you can download it via the link below. If you have never added a specific feature to your WordPress site, we recommend you start by reading our dedicated guide (link below).

Guide – Add a feature to your WordPress site

Download Code Snippets on wordpress.org


2|Prérequis

Here is the list of extensions required for this snippet to work properly. Make sure to install them before activating the snippet.

WooCommerceNecessary for selling virtual products on your site

3|Snippet

Here is the snippet to use. The comments inside the code will guide you on how this snippet works.

Assurez-vous de cocher la case « Run snippet everywhere » avant d’activer le snippet.

/**
 * Affiche un badge "Nouveau" sur les produits récents
 */
add_action( 'woocommerce_before_shop_loop_item_title', 'lws_afficher_badge_nouveau', 10 );

function lws_afficher_badge_nouveau() {
    global $product;

    // Durée pendant laquelle le produit est considéré comme "nouveau" (en jours)
    $jours_nouveau = 30;

    // Récupération de la date de publication du produit
    $date_publication = get_the_date( 'U', $product->get_id() );

    // Vérification : si le produit a moins de X jours
    if ( ( time() - ( $jours_nouveau * 24 * 60 * 60 ) ) < $date_publication ) {
        echo '<span class="badge-nouveau" style="            position:absolute;            top:10px;            left:10px;            background-color:#e74c3c;            color:#fff;            padding:5px 10px;            font-size:12px;            border-radius:3px;            z-index:5;        ">Nouveau</span>';
    }
}

Why is this code useful?

This snippet frees you from plugins like “machins-pro-badge-ultimate” that slow down your site. It gives you complete control over the appearance, duration, and display logic of the “New” badge. In short: a lightweight, elegant solution that is 100% tailored to your theme.
And above all, it flatters your visitors with the illusion of novelty—the eternal fuel of commerce.

Take it a step further

This type of customization demonstrates how WooCommerce can be extended through WordPress filters and actions. If you'd like to further customize your loyalty program, consider consulting the WooRewards documentation or hiring an experienced WordPress developer (see our Custom Development page).

Our Plugins

We have created powerful and widely acclaimed plugins for WooCommerce. Boost your sales with our solutions

WooRewards

Discover the most powerful loyalty plugin for WooCommerce. Simple or tiered systems, referrals, social networks, badges and achievements, you will find all the tools to build YOUR loyalty program

Learn More

VIP Membership

VIP Memberships is a complete membership management tool for your WooCommerce site. Sell subscriptions to your customers and offer them benefits such as preferential prices or exclusive products.

Learn More

Virtual Wallet

Offer your customers a virtual wallet on your website. Let them save money by purchasing your products and use this credit on future purchases. This extension also offers a complete gift card tool

Learn More

Referral Codes

Win new customers with this complete SEO tool. Whether through influencers or simple referrers, reward them and the new customers they bring

Learn More

Leave a comment

You must be logged in to post a comment.