Skip to content
Site Under Re-Design: We're updating & improving the docs! Some layouts or content may look broken or inconsistent during this process. If you’re unable to find an article, please use the search bar while we restructure and optimize the sidebar navigation.

Display “New” Badge for WooCommerce Product

/*
 * Adds a new badge to product entry for any product added in the last 30 days.
 * Simply add to child theme's functions.php file then add some css to your site to style it.
 * If you want the badge to be a part of the "equal height" content then use 'PHP_INT_MAX' for the
 * priority instead of 20
 *
 */
add_action( 'woocommerce_before_shop_loop_item_title', function() {
	$postdate      = get_the_time( 'Y-m-d' ); // Post date
	$postdatestamp = strtotime( $postdate );  // Timestamped post date
	$newness       = 30;                      // Newness in days
	if ( ( time() - ( 60 * 60 * 24 * $newness ) ) < $postdatestamp ) {
		echo '<div class="woo-entry-new-badge">' . esc_html__( 'New', 'total' ) . '</div>';
	}
}, 20 );
All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
Related Snippets
No related snippets found
Back To Top