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.

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.

Thanks and i will always give you little tips to help you along the way, cheers!
Thanks Perry,
Do you also know how to remove the strikethrough from the original price?
Steve
My bad – sorry Terry!
Thaks for tutorial, can you advise how to add a countdown ?
Hi, let me try myself first, will update here soon.
Hi, thanks for tutorial. I wonder how are you getting discount value and outputting it?
Thanks,
Awesome, thanks Terry!
Hello pipdig, thank you. Do share with your friend if they need that, cheers!
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
Hi gopi, have you put the code into your functions.php file at the active theme folder?
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
Hi King, thanks for the suggestion, i will talk about that in my next tutorial.
Dear Terry
I’d love to use your code but text appaears near price Tag in my product page.
Can you help me please?
All the bests!
Hi arianna, you can put extra spaces between price and the text. Do try the code below:
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.
hi Terry,
I am using the Variable product type, and your code is not working with it.
Any suggestion? That would be really helpful.
Thaks for tutorial, can you advise how to add a countdown ,too ^_^
Waitting …
Hi, “related products” display too (i dont want it ) , can only display product page ?
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);
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 ?
thanks so much! worked like a charm. Appreciate the help. i’ve never seen code inserted through a function file.
Hi Ron, glad it helped. We can customize WordPress function by using functions.php, sometimes I eill packed the code into a plugin.
There is a timer plugin to do that more fancy and out of the box, take a look: http://codecanyon.net/item/woocommerce-sales-countdown/7906953
Great code! How can I display the date for variable products on sale?
Yes, can you please help us out… Just like Elena we want this to work with Variable Products…. Please! Help us out.. lol
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?
Thanks, for the code. I’m grateful. It works for single product. But once I use variation products, it doesn’t show the end date.
Exactly what i looking for..Thank you so much for your time.
Hi sir,
Please
I added your 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( ”, ‘ (Offer till ‘.$sales_price_date_to.’)‘, $price );
}
else
{
return apply_filters( ‘woocommerce_get_price’, $price );
}
}
On my functions.php file, but it is not working !!!
Please, Help!!!
Best regards
A.J.
Hi sir,
Your code is working very fins,
Please,
Do you know , how can i view a schedule time for a regular price ?
Best regards
A.J.
Hello Terry,
Thanks this code ! And how to display Sales End Date on the variable products page ? Can you help for me?
Thanks
Hey Terry,
woocommerce_get_price_html is not being fired for products with variation. So your code only works for single products.
Any idea how to fix that?
Thank you!
Thank you for the sale of code!
How can I remove the date of designation of the year?
Can We do also “from date”?
Hi, your code works like magic. However,
1. kindly what the code will be if it were to show days to end of the sale instead? E.g Sale ends in 1day/2days/3days etc.
2. I need it to display on the Sale Products page too.
I will really appreciate a response, please.
Thank you.
Much love,
from Africa.
Is this still valid for WP 4.9 and WC 3.2.4 ?
I am using a child theme and put the filter below the setup for the Child Theme Plug-in and it does not work. Any clue as to what I’m doing wrong?:
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( ”, ‘ (Offer till ‘.$sales_price_date_to.’)‘, $price );
}
else
{
return apply_filters( ‘woocommerce_get_price’, $price );
}
}
// AMK – 171121 End
//
Dam. This doesn’t see to work for WP Version 4.9.6 and Woo Version 3.4.3. I’d love to see an update on this post of possible! Thanks.