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        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @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

  • WooCommerce: Display Total Discount / Savings @ Cart & Checkout
    If you love Ecommerce as much as I do, and are passionate about Sales Conversion Rate and reducing Shopping Cart Abandonment, today’s snippet will come in handy. Besides, this is officially the first guest blog on Business Bloomer (have ideas? Send me your proposal here)… so let me officially introduce you to today’s author: Jamie […]
  • WooCommerce: Display % Discount @ Shop Page
    Default WooCommerce shows a “Sale” badge if the item is on sale – but what about showing the exact sale percentage instead? I implemented this for one of my freelance clients so here you go with the easy-peasy solution. Enjoy!
  • WooCommerce: Display Prices as “Was $$$ – Now $$$ – Save $$$”
    Many retailers use this price tag strategy quite successfully. And displaying the amount of savings can increase your ecommerce store conversion rate as well ๐Ÿ™‚ So, turning simple product default pricing from “$30 $20″ to “Was $30 – Now $20 – Save $10” is quite easy. With a little CSS you can also style the […]
  • WooCommerce: Set / Override Product Price Programmatically
    There are times when the edit product page settings are not enough. Yes, you usually set regular and sale price via the price fields under “Product Data”; however sometimes you may have to override those prices via code, because you’re running a special promotion, you don’t want to manually change thousands of prices or maybe […]
  • WooCommerce: How to Edit Product Prices in Bulk?
    I’m pretty sure that during one of those Black Friday sales all you wanted to do was to apply a bulk discount to your WooCommerce products without having to generate a coupon code. Let’s not forget that despite coupons are trackable and you can assess your marketing efforts with their usage statistics, requiring the user […]

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

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 *