A simple, powerful and independent e-commerce platform.
Sell anything with ease.

Add ‘New’ badge for recently added items

This code puts a ‘New!‘ badge on items that have been added recently. The setting in the example below is for products added in the last 30 days. A class has also been included to match the “onsale” button, but you can change the class name if you want to style it differently.

		/**
 * Add 'New' badge for recently added items
 */

add_action('woocommerce_before_shop_loop_item_title', 'cc_new_badge_shop_page', 3);

function cc_new_badge_shop_page() {

  global $product;
  $newness_days = 30;
  $created = strtotime($product->get_date_created());
  if (( time() - (60 * 60 * 24 * $newness_days )) < $created ) {
    echo '<span class="onsale">' . esc_html__('New!', 'woocommerce') . '</span>';
  }

}
	
View Raw Code ID: 9870