1

Let me say about the condition I need to ask:

I display the start sale and end sale for a product on WooCommerce. The code on loop like this:

    <?php $thepostid = get_the_ID();
    if ( $date = get_post_meta( $thepostid, '_sale_price_dates_from', true ) ) {
    $sale_price_dates_from =
     '<div class="fromsale">' .
     '<span class="promodesc">' .  esc_html__( 'Sale start:', 'mytheme' ). '</span>' .
    '<span class="m">' . date_i18n( 'M', $date ) . '</span> ' .
    '<span class="d">' . date_i18n( 'j', $date ) . '</span> ' .
    '</div>' 
    ;

    } else {
    $sale_price_dates_from =
     '<div class="endsale">' .
     '<span class="promodesc">' .  esc_html__( 'No Schedule', 'mytheme' ). '</span> ' .
    '</div>' 
    ; }
    echo $sale_price_dates_from ;
    ?>


    <?php $thepostid = get_the_ID();
    if ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) {
    $sale_price_dates_to =
     '<div class="endsale">' .
     '<span class="promodesc">' .  esc_html__( 'Sale end:', 'mytheme' ). '</span>' .
    '<span class="m">' . date_i18n( 'M', $date ) . '</span> ' .
    '<span class="d">' . date_i18n( 'j', $date ) . '</span> ' .
    '</div>' 
    ;

    } else {
    $sale_price_dates_to =
     '<div class="endsale">' .
     '<span class="promodesc">' .  esc_html__( 'No Schedule', 'mytheme' ). '</span> ' .
    '</div>' 
    ; }
    echo $sale_price_dates_to ;
    ?>

The result is like this:

 Sale start: May 13

 Sale end: May 22

I am curious, how to get times range between the start and the end? In this case I want to display the countdown like this (for example):

 Sale will be end: 7days 20hours 33minutes 22seconds.

Can anyone help me?

Thank for any kind of helps.

Mailmulah
  • 61
  • 2
  • 9
  • 1
    see this - http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php – line88 May 21 '16 at 11:15
  • Some of answer on your link look promising. Will try. – Mailmulah May 21 '16 at 11:52
  • the idea is that you get two dates and calculate the differences of it using php its not about wordpress or woocommerce - http://php.net/manual/en/function.date-diff.php... – line88 May 21 '16 at 14:33
  • Yes, this is what I need. Thank you @MancharyManchaary – Mailmulah May 21 '16 at 18:28

0 Answers0