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.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

Your email address will not be published. Required fields are marked *

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers