Add Sales End Date for WooCommerce Product Price

Share this:

There is always a situation when your customers will ask you whether the product sales price has a limited period. This always happen especially for a “Last Minute Sale”, “Christmas Eve Sale” or “Holiday Sale”.

In current WooCommerce product page, you mostly will see the strikethrough for normal price and beside will have the sales price. That’s it.

Normal Sales Price Layout for WooCommerce Product Page

Normal Sales Price Layout for WooCommerce Product Page

So in this tutorial, i will teach you all a simple way to add “Offer till [date end]” text beside the sales price. You can also change the text without any effort.

Let’s begin.

Step 1: Open functions.php file in your theme folder, add below code:

add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
function custom_price_html( $price, $product ){
	global $post;
	$sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
	if(is_single() && $sales_price_to != "")
	{
		$sales_price_date_to = date("j M y", $sales_price_to);

		return str_replace( '</ins>', ' </ins> <b>(Offer till '.$sales_price_date_to.')</b>', $price );
	}
	else
	{
		return apply_filters( 'woocommerce_get_price', $price );
	}
}

Step 2: Save the file. If you want to change the text for above example, just change “Offer till” phrase to whatever you want, ok.


Step 3: Done, refresh your product page that has ongoing sales that you have schedule start and end date.

Add Price Sales End Date at WooCommerce Product Page

Add Price Sales End Date at WooCommerce Product Page

Thanks and i will always give you little tips to help you along the way, cheers!

26 Comments

  1. Hi Terry,

    Thanks for the code. but unfortunately it’s not working for me. When put that code into function.php. my site is going down and my getting blank white pages.but i really want to show this expiration date just beside to my product price. Any help ?

    cheers

  2. Hi Terry,
    Can you talk about Countdown for a single product?
    Ex: I want Product name “ABC” with sale $19 & sale off $15 in 3 days (show countdown hours/minutes/seconds).

    Thanks,
    King

  3. Hi arianna, you can put extra spaces between price and the text. Do try the code below:

    add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
    function custom_price_html( $price, $product ){
        global $post;
        $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
        if(is_single() && $sales_price_to != "")
        {
            $sales_price_date_to = date("j M y", $sales_price_to);
     
            return str_replace( '</ins>', ' </ins> &nbsp;&nbsp;&nbsp;<b>(Offer till '.$sales_price_date_to.')</b>', $price );
        }
        else
        {
            return apply_filters( 'woocommerce_get_price', $price );
        }
    }
    
  4. Terry, Hi!
    My question pertains to the schedule area of the:
    woo-product/product-data/general (back-end)
    Where we can schedule (via the calender) YY-MM-DD of the sale.
    Can I add HH:MM to that code to get hours and minutes?
    Sorry if this is a little off base, I’ve been searching everywhere for documentation and this is the closest I’ve found on the subject.
    Any ideas would be helpful, thank you again.

  5. hi Terry,
    I am using the Variable product type, and your code is not working with it.
    Any suggestion? That would be really helpful.

  6. Hi Lee, you can put below code at functions.php in your them folder:

    function wc_remove_related_products( $args ) {
    return array();
    }
    add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);

  7. Thanks, but you misunderstood what I meant -.-

    I mean, your function (Add Sales End Date) will be displayed in the above related merchandise.

    Can be displayed only in one place ?

  8. thanks so much! worked like a charm. Appreciate the help. i’ve never seen code inserted through a function file.

  9. Yes, can you please help us out… Just like Elena we want this to work with Variable Products…. Please! Help us out.. lol

  10. It’s possible to add more than one schedule?
    I have to sell a course by October 20.
    Registering before August 31 pay 300.
    Registering before September 31 pay 400.
    Enrolling in October pay 500 (regular price)
    So I should add two dates sale price.
    Maybe I have to use some custom field?

Leave a Comment.