Product Page

WooCommerce Show Sale Price Dates On Product Page

WooCommerce product page showing the sale price dates

Pre-Requisites

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.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER