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

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        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */

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

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

4 thoughts on “WooCommerce: Display Sale Price End Date @ Shop & Single Product Page

  1. Is there a way to add it above the add to cart button?

    1. For sure, just check the visual hook guide for the Shop page and pick the right hook

  2. Can this be displayed only on the single product page? The text is being cut off on the product archive page and partially hidden under the SALE badge.

    1. Sure!

      if ( is_product() && $product->get_date_on_sale_to() ) { ...
      
Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *