PHP 'opening Hours' - 带有自定义字段的时间

PHP 'opening Hours' - Time with custom field

我正在使用此代码显示简单的 'open' 或 'closed' 消息。代码取自这个问题并稍作调整 - 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>';
    }
?>

此代码适用于手动输入的开放时间,我遇到的问题是当我尝试为开放时间添加 (ACF) 自定义字段时,它停止运行 - 作为周日的示例如下?

elseif ($weekday == "Sunday") {
        $open_from = "<?php the_field('sunday_open','options'); ?>";
        $open_to = "<?php the_field('sunday_closed','options'); ?>";
    }

只要我在代码中输入字段,它就会显示 'Sorry , We Are Closed',即使开放时间已在 ACF 选项时间选择器中设置。当我将其改回并手动输入时,例如 -

$open_from = "10:00";
$open_to = "15:00";

它再次工作并正确给出消息 'We Are Open Now !'。

我运行这个调试

<?php 

$time = get_field('sundays_open','options');

echo '<pre>';
    var_dump( $time );
echo '</pre>';

?>

它Returns这个-

string '10:00' (length=5)

ACF 时间字段的输出设置为 H:i

任何人都可以指出这里可能有什么问题吗?

您要在 PHP 个标签内放置 PHP 个标签?

尝试,

elseif ($weekday == "Sunday") {
    $open_from = the_field('sunday_open','options');
    $open_to = the_field('sunday_closed','options');
}