I'm using this code to display a simple 'open' or 'closed' message. the code was taken from this question and adapted slightly - Opening hours in PHP
<?php
date_default_timezone_set('Europe/London'); // timezone
$weekday = date(l); // today
//print $weekday; // Debug
//print date("H:i"); // debug
// Set open and closing time for each day of the week
if ($weekday == "Saturday") {
$open_from = "10:00";
$open_to = "14:00";
}
elseif ($weekday == "Sunday") {
$open_from = "10:00";
$open_to = "15:00";
}
else {
$open_from = "10:00";
$open_to = "17:00";
}
// now check if the current time is before or after opening hours
if (date("H:i") < $open_from || date("H:i") > $open_to ) {
echo '<div class="opening">Sorry , We Are Closed</div>';
}
// show open message
else {
echo '<div class="opening">We Are Open Now !</div>';
}
?>
This Code works fine with the opening times entered manually , the problem i'm having is when i try and add a (ACF) custom field for the opening times , it stops functioning - As an Example for Sunday as below ?
elseif ($weekday == "Sunday") {
$open_from = "<?php the_field('sunday_open','options'); ?>";
$open_to = "<?php the_field('sunday_closed','options'); ?>";
}
As soon as i enter the fields into the code , it will say 'Sorry , We Are Closed' , even though the opening times have been set in the ACF options time picker. When i change it back and enter it manually , like -
$open_from = "10:00";
$open_to = "15:00";
It works again and gives the message 'We Are Open Now !' correctly.
I ran this debug
<?php
$time = get_field('sundays_open','options');
echo '<pre>';
var_dump( $time );
echo '</pre>';
?>
and it Returns this -
string '10:00' (length=5)
the output for the ACF time field is set to H:i
Can anyone point out what might be wrong here ?