WooCommerce Show Sale Price Dates On Product Page

WooCommerce product page showing the sale price dates


There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

This snippet allows you to show the date range a product is on sale if you had set a sale price in the editor.

 * Snippet Name:	WooCommerce Display Sale Price Dates
 * Snippet Author:	ecommercehints.com

add_filter( 'woocommerce_get_price_html', 'ecommercehints_display_sale_price_dates', 100, 2 );
function ecommercehints_display_sale_price_dates( $price, $product ) {
    $sales_price_from = get_post_meta( $product->id, '_sale_price_dates_from', true );
    $sales_price_to   = get_post_meta( $product->id, '_sale_price_dates_to', true );
    if ( is_product() && $product->is_on_sale() && $sales_price_to != "" ) {
        $sales_price_date_from = date( "l jS F", $sales_price_from );
        $sales_price_date_to   = date( "l jS F", $sales_price_to );
        $price .= "<br><small>Sale from " . $sales_price_date_from . ' to ' . $sales_price_date_to . "</small>";
    return $price;

Snippet Benefits

  • If a product is on sale, and you have scheduled dates the sale begins and ends, display the date range of the sale under the price on the single product template.
  • Make is super clear to customers the your store is going to end the sale, therefore encouraging them to buy now with urgency.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers