Ask your WordPress questions! Pay money and get answers fast! (more info)

woocommerce - display Special Price date range WordPress


Hi, i need to display the Special Price date range in product-content.php

I want to display the custom field "_sale_price_dates_to "

I tryed with this code but doesn't work:

<?php echo get_post_meta($post->ID, '_sale_price_dates_to', true) ?>

The previous code is the only that works, but display a strange number like: 1353628800

following codes doesn't works:

<?php echo get_post_meta($post->ID, 'sale_price_dates_to', true) ?>

$sale_price_dates_to = get_post_meta( $product_id, '_sale_price_dates_to', true);

check this page :

anyone could help me ?

Answers (2)


Kyle answers:

You just have to convert that number '1353628800'. That is actually the date string, You can easily format that anyway you want with the date() php function

Kyle comments:

Try this:

$date = get_post_meta($post->ID, '_sale_price_dates_to', true);

echo date_format($date, 'Y-m-d H:i:s');

Manlio Ma comments:

Hi this code returns an error ! thanx for your answer!

Kyle comments:

You have a variable up there: $product_id . What does that go to?


Dbranes answers:

Hi, this is probably the unix-time you got there, try

<?php echo date("Y-m-d",get_post_meta($post->ID, '_sale_price_dates_to', true)); ?>

Manlio Ma comments:

works perfectly ! thank you very much!

Manlio Ma comments:

Hi Dbranes, from this code, are you able to give me a code to display a countdown timer ? If yes, quote me thanx