I got this code from here ( Display woocommerce sale end date )
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 );
}
}
This only displays the Sale Date to. How do I make it display the sale date from till sale date to?
I tried editing this line:
return str_replace( '</ins>', ' </ins> <b>(Offer till '.$sales_price_date_to.')</b>', $price );
to
return str_replace( '</ins>', ' </ins> <b>(Offer from '.$sales_price_date_from.' till '.$sales_price_date_to.')</b>', $price );
but it doesn't display the sale date from.
So can someone please tell me how I display both the sale date from and sale date to?
I've made a plugin exactly for this (100% free, no ads and no hidden features).
The main difference from others on the store is that it also works with Variations (even if each variation has different dates).
https://wordpress.org/plugins/woo-on-sale-information/
Also, it was developed with simplicity in mind and with filters for developers to be able to tweak it without issues (the code is well documented also).
Give it a look ;)
I have tried it on my site and it works for me.