这是一个粗糙的PHP脚本,您首先需要了解WordPress的概念hooks
例如在插件中实现它。请了解这些主题。
好吧,作为对你评论的回应,这取决于你的项目/网站的工作流程,以确切地知道在什么时候触发代码。
这是一个例子,没有必要as you expect
基本上,它应该是这样的代码:
add_action( \'init\', \'openning_hours_func\' );
function openning_hours_func() {
date_default_timezone_set(\'Europe/Stockholm\'); // 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 == "Friday") {
$open_from = "11:00";
$opten_to = "21:45";
}
elseif ($weekday == "Saturday" || $weekday == "Sunday") {
$open_from = "12:00";
$open_to = "21:45";
}
else {
$open_from = "11:00";
$open_to = "20:45";
}
// now check if the current time is before or after opening hours
if (date("H:i") < $open_from || date("H:i") > $open_to ) {
print "Closed!";
}
// show the checkout button
else {
print "Open!";
}
}