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 '' . 'NEW!' . ''; // 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 '' . 'NEW!' . ''; // The "NEW!" text with the sale badge styling
}
}