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.

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.