Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

woocommerce - display Special Price date range WordPress

  • SOLVED

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) ?>



<?php
$sale_price_dates_to = get_post_meta( $product_id, '_sale_price_dates_to', true);
print_r($sale_price_dates_to);
?>


check this page : http://www.kickproduction.it/gsmart/

anyone could help me ?

Answers (2)

2012-11-16

Kyle answers:

You just have to convert that number '1353628800'. That is actually the date string, http://php.net/manual/en/function.strtotime.php. 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?

2012-11-16

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