Product Archive, Product Page

WooCommerce Show “NEW” Badge On Newly Added Products

WooCommerce new badge showing on newly added products on archive and single product page

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

This guide shows you how to add the next “NEW” on products which have been added to your WooCommerce store in the last 10 days. Of course you can output whatever text you like and change the number of days to meet your requirements. This guide will display the new badge adjacent to the SALE badge if the product were to have a sale price applied.

/**
 * Snippet Name:	WooCommerce Show "NEW" Badge On Newly Added Products
 * Snippet Author:	ecommercehints.com
 */

// Show the NEW badge on the archive loop item
add_action( 'woocommerce_after_shop_loop_item_title', 'ecommercehints_product_archive_new_badge', 1 );
function ecommercehints_product_archive_new_badge() {
   global $product;
   $days_to_show = 10; // Show the new badge for 10 days
   $product_published_date = strtotime( $product->get_date_created() );
   if ( ( time() - ( 60 * 60 * 24 * $days_to_show ) ) < $product_published_date ) {
      echo '<span class="onsale">' . 'NEW!' . '</span>'; // The "NEW!" text with the sale badge styling
   }
}

// Show the NEW badge on the single product template
add_action( 'woocommerce_single_product_summary', 'ecommercehints_single_product_new_badge', 3 );
function ecommercehints_single_product_new_badge() {
   global $product;
   $days_to_show = 10; // Show the new badge for 10 days
   $product_published_date = strtotime( $product->get_date_created() );
   if ( ( time() - ( 60 * 60 * 24 * $days_to_show ) ) < $product_published_date ) {
      echo '<span class="onsale">' . 'NEW!' . '</span>'; // The "NEW!" text with the sale badge styling
   }
}

Snippet Benefits

  • Let customers know which products have been recently added to your store by displaying a “NEW” badge on both the product archive loop items and the single product template.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER