Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

“New” badge on recent products

Products added in the last 30 days show a “New” label in the shop and category pages.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Needs WooCommerce
  • Category WooCommerce
  • Tested with WordPress 7.1, WooCommerce 11.1
PHP
<?php

add_action(
	'woocommerce_before_shop_loop_item_title',
	static function () {
		global $product;
		$days = 30;
		if ( $product instanceof WC_Product && $product->get_date_created() && $product->get_date_created()->getTimestamp() > time() - $days * DAY_IN_SECONDS ) {
			echo '<span class="snipfire-new">' . esc_html__( 'New', 'woocommerce' ) . '</span>';
		}
	},
	9
);
add_action(
	'wp_head',
	static function () {
		echo '<style>.woocommerce ul.products li.product{position:relative}.snipfire-new{position:absolute;top:8px;right:8px;z-index:2;background:#2346c9;color:#fff;font-size:.75rem;font-weight:600;text-transform:uppercase;letter-spacing:.04em;padding:4px 8px;border-radius:3px}</style>';
	}
);

Good to know

Change $days to suit your shop. For classic shop templates.

In these packs

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.