Php 创建店铺时钟功能-打开/关闭&;取决于时间的事件
所以我有一个正常运行的代码。我得到了一些帮助,因为尽管我对自己的编码技能(相当新)相当有信心,但时间避开了我,我发现确定它在PHP中的工作方式很困惑 我希望创建一个函数,作为我的存储时钟,并返回“打开”-“关闭”-“1小时关闭”的结果,我可以在其他函数中使用 例如:Php 创建店铺时钟功能-打开/关闭&;取决于时间的事件,php,wordpress,datetime,woocommerce,clock,Php,Wordpress,Datetime,Woocommerce,Clock,所以我有一个正常运行的代码。我得到了一些帮助,因为尽管我对自己的编码技能(相当新)相当有信心,但时间避开了我,我发现确定它在PHP中的工作方式很困惑 我希望创建一个函数,作为我的存储时钟,并返回“打开”-“关闭”-“1小时关闭”的结果,我可以在其他函数中使用 例如: if ( store_clock() == 'open' ) { echo 'Open'; } elseif ( store_clock() == '1_hr_left' ) { echo 'You have 2
if ( store_clock() == 'open' ) {
echo 'Open';
}
elseif ( store_clock() == '1_hr_left' ) {
echo 'You have 27 mins and 12 secs to place an order' );
else {
echo 'Sorry, we are closed.';
}
我目前有以下代码,它在关闭时间、正确显示剩余倒计时时间等方面工作正常。问题是我没有打开时间,我更愿意将代码拆分-允许我使用store\u clock()
函数触发整个站点的其他事件。。。不仅仅是关门柜台
要做到这一点,我假设我需要2到3个不同的功能,而不仅仅是1。。。但是我感到很困惑。谢谢你的帮助。(PS.get_field()
正在调用ACF值)
功能卫星时钟(){
$the_time=当前_时间(“时间戳”);
$exact_time=gmdate('g:ia',$the_time);
$weekday_close=get_字段('weekday_close','options');
$sat_close=get_字段('sat_close','options');
$sun_close=get_字段('sun_close','options');
//从sun sat开始在这里设置您的截止时间
$closing_times=数组($sun_close,$weekday_close,$weekday_close,$weekday_close,$weekday_close,$weekday_close,$weekday_close,$weekday_close,$weekday_close,$weekday;
if($closing_times[日期('w',当前_时间('timestamp'))]!==false){
$closing_time=strottime(sprintf('%s%s',日期('dfy',当前_时间('timestamp')),$closing_时间[日期('w',当前_时间('timestamp')))));
如果($closing_time-current_time('timestamp')>0&&$closing_time-current_time('timestamp')<1800){
echo'最后一次呼叫;
?>
var timeLeft=;
//每1秒更新一次倒计时
var x=setInterval(函数(){
//分钟和秒的时间计算
var分钟=数学楼层(时间限制/60);
var秒=数学地板(时间间隔%60);
//使用id=“demo”在元素中显示结果
document.getElementById(“即将关闭计时器”).innerHTML=“您有“+minutes+”minutes“+”“+seconds+”秒下单。”;
//如果倒计时结束,写一些文字
如果(时间间隔<0){
净间隔(x);
document.getElementById(“即将关闭计时器”).innerHTML=“今天关闭”;
}
时间限制--;
}, 1000);
function sat_clock() {
$the_time = current_time('timestamp');
$exact_time = gmdate('g:ia', $the_time);
$weekday_close = get_field('weekday_close', 'options');
$sat_close = get_field('sat_close', 'options');
$sun_close = get_field('sun_close', 'options');
// Set your closing times here from sun-sat
$closing_times = array( $sun_close, $weekday_close, $weekday_close, $weekday_close, $weekday_close, '7:31 pm', $sat_close );
if ( $closing_times[date( 'w', current_time('timestamp') )] !== false ) {
$closing_time = strtotime( sprintf( '%s %s', date( 'd F Y', current_time('timestamp') ), $closing_times[date( 'w', current_time('timestamp') )] ) );
if ( $closing_time - current_time('timestamp') > 0 && $closing_time - current_time('timestamp') < 1800 ) {
echo '<strong>LAST CALL</strong><p class="m-0" id="closing-soon-timer"></p>';
?>
<script>
var timeLeft = <?php echo $closing_time - current_time('timestamp'); ?>;
// Update the count down every 1 second
var x = setInterval(function() {
// Time calculations for minutes and seconds
var minutes = Math.floor(timeLeft / 60);
var seconds = Math.floor(timeLeft % 60);
// Display the result in the element with id="demo"
document.getElementById("closing-soon-timer").innerHTML = "You have <strong>" + minutes + "</strong> minutes " + "<strong>" + seconds + "</strong> seconds to place an order.";
// If the count down is finished, write some text
if (timeLeft < 0) {
clearInterval(x);
document.getElementById("closing-soon-timer").innerHTML = "Closed for today";
}
timeLeft--;
}, 1000);
</script>
<?php
} elseif ( $closing_time - current_time('timestamp') < 0 ) {
echo "<p>Closed for today</p>";
} else {
echo "<p>Opened</p>" . gmdate('g:ia', $closing_time);
var_dump($exact_time);
}
} else {
echo "<p>Closed for today</p>";
}
}
add_action( 'woocommerce_archive_description', 'sat_clock' );