Menu Close

WooCommerce: Display Sale Price End Date @ Shop & Single Product Page

default

WooCommerce allows you to “schedule” the product sale price – you can define a start date and an end date, so that you can run your promotion automatically.

However, for some reason, this information is only visible to the admin. It would be awesome to show the “sale price end date” to customers as well, don’t you think? So, let’s do it!

The “ends 31 May” is the result of my customization. It reads the “sale price end date” and prints it beside the Sale badge. Cool, isn’t it?

PHP Snippet: Add Sale Price End Date to Sale Badge @ WooCommerce Shop, Archive, Product Pages

/**
 * @snippet       Sale Price End Date @ WooCommerce Archive & Single Product
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_sale_flash', 'bbloomer_sale_end_date', 9999, 3 );

function bbloomer_sale_end_date( $html, $post, $product ) {
	if ( $product->get_date_on_sale_to() ) return $html . ' (ends ' . gmdate( 'd M', $product->get_date_on_sale_to()->getTimestamp() ) . ')'; 
	return $html;
}
View Source
Posted in WooCommerce Tips