I am trying to show the hours and minutes remaining from the current time and 13:00/1pm.
We have two conditions:
If the current hour is < 13:00 (1 pm), the delivery is 7 weekdays and the user is shown how much time is left until the 1 pm deadline (e.g. 1 hour 22 minutes at 11:38).
If the current hour is > 13:00 (1 pm), the delivery is 8 weekdays and the user should be shown how much time is left until the next day at 1 pm (e.g. 23 hours 59 minutes at 13:01).
The second if-statement below shows nothing in the browser (html echo).
Prior to today reaching 13:00 (1 pm), the first if-statement worked and showed e.g. 2 hours remaining at 11:00 (11 am).
add_action( 'woocommerce_after_add_to_cart_form', 'delivery_info' );
function delivery_info()
{
date_default_timezone_set( 'Europe/London' );
// if 1 pm
if ( date('H') < 13 ) {
$del_day = date( 'l jS F' , strtotime ( '7 weekdays' ) );
$today = strtotime('today 13:00');
$tomorrow = strtotime('tomorrow 13:00');
$now = time();
$timeLeft = ($now > $today ? $tomorrow : $today) - $now;
$timeResult = (gmdate("H:i:s", $timeLeft));
$hour = date('H', $timeLeft);
$min = date('i', $timeLeft);
}
// if after 1PM
elseif ( date('H') > 13 ) {
$del_day = date( 'l jS F' , strtotime ( '8 weekdays' ) );
$today = strtotime('today 13:00');
$tomorrow = strtotime('tomorrow 13:00');
$now = time();
$timeLeft = ($now > $today ? $tomorrow : $today) - $now;
$timeResult = (gmdate("H:i:s", $timeLeft));
$hour = date('H', $timeLeft);
$min = date('i', $timeLeft);
}
// HTML output
echo <<<HTML
<br>
<div class="woocommerce-message est-delivery"
style="white-space: pre-line;
text-align: left;
display: inline-block;
">
<h4>Standard Delivery</h4>
<br>
<span style='color:#000000'>
Order arrives <b>{$del_day}</b>,
</span>
<br/>
<span style="color:#47bab5">
order within {$hour}hrs {$min}mins
</span>
</div>
HTML;
}
What have I done wrong? And is there a better way to achieve the above?