I am trying to compare two dates, the current time and whether it is smaller than the dates I set.
Unfortunately, the condition does not want to work in any way
function is_store_open_to_thursday($html, $product)
{
date_default_timezone_set('Europe/Warsaw');
$datetime1 = new DateTimeImmutable('thursday 12:00:00');
$datetime2 = $datetime1->modify('+3 days');
$now = time();
$html = '<form action="' . esc_url($product->add_to_cart_url()) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input(array(), $product, false);
if ($now >= strtotime($datetime1) && $now <= strtotime($datetime2)) {
$html .= '<p>WORK</p>';
}
else{
$html .= 'NOT WORKING';
}
$html .= '</form>';
return $html;
}
2
Answers
Variables
$datetime1
anddatetime2
are objects.So if you pass them to function
strtotime
you will should to see in your php.log file warnings:<b>Warning</b>: strtotime() expects parameter 1 to be string, object given in
.Change yor conditions statement to:
It’s not very cool, but should works: