Site logo

Archived topic

New badge for WooCommerce

3 replies · Started by Katja on August 28, 2018

Viewing posts 1–4 of 4

Hello GeneratePress Team,

we have Woocommerce up and running and have the sale flash activated via the customizer (display over the inage).

Is it possible to display a flash for new products, say added within the last thirty days, via a hook? Ieally this would float to the left (the sale flash floats to the right) also over the image.

Any pointers would be appreciated. Is this something that imght usefully be added to the GP WooCommerce offering in future?

Thanks for any help and best wishes to you all

Roger

Hi there,

so the only up to date plugin (aside of Codecanyon) is:

https://woocommerce.com/products/woocommerce-advanced-product-labels/

Or you can code it in using this function:

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 );

You can change the woocommerce_before_shop_loop_item_title hook if you wish. A visual hook guide link below. And the woo-entry-new-badge class can be used to style it.

https://businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/

I'll make Tom aware of the possible feature request :)

Hello David,

thank you for the helpful pointers. Gives me something to get me teeth into.

Best wishes

You're welcome. :)

This archived topic is closed to new replies.