Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 商店时钟-根据商店时间显示30分钟倒计时_Php_Wordpress_Datetime_Woocommerce - Fatal编程技术网

Php 商店时钟-根据商店时间显示30分钟倒计时

Php 商店时钟-根据商店时间显示30分钟倒计时,php,wordpress,datetime,woocommerce,Php,Wordpress,Datetime,Woocommerce,我想在我的电子商务商店关门前30分钟展示一分钟倒计时。基本上,你有29分32秒的时间下单 我有一个当前脚本,它从几个ACF(高级自定义字段)时间选择器字段中提取存储时间。我还拉我的商店日期和时间正确。。。我只是不知道如何在30分钟前显示消息并初始化倒计时 function sat_clock() { $format = get_option('date_format') . ' ' . get_option('time_format'); $hour = the_field('w

我想在我的电子商务商店关门前30分钟展示一分钟倒计时。基本上,你有29分32秒的时间下单

我有一个当前脚本,它从几个ACF(高级自定义字段)时间选择器字段中提取存储时间。我还拉我的商店日期和时间正确。。。我只是不知道如何在30分钟前显示消息并初始化倒计时

function sat_clock() {
    $format = get_option('date_format') . ' ' . get_option('time_format');
    $hour = the_field('weekday_open', 'options');
    $times = array(
        'mon' => '9:00 AM - 9:00 PM',
        'tue' => '9:00 AM - 9:00 PM',
        'wed' => '9:00 AM - 9:00 PM',
        'thu' => '9:00 AM - 9:00 PM',
        'fri' => '9:00 AM - 9:00 PM',
        'sat' => '11:00 AM - 6:00 PM',
        'sun' => 'closed'
    );

    print date_i18n($format, current_time('timestamp'));
    print $hour;

}
add_action( 'woocommerce_archive_description', 'sat_clock' );

只需检查当前时间和当天关闭时间的差异。如果时间少于30分钟(1800秒),则显示从当前时间与当天结束时间之差开始的一点时间

add_action( 'woocommerce_archive_description', 'sat_clock' );
function sat_clock() {

    $store_times = array(
        false, //Sunday 
        array( //Monday
            'open' => '09:00 AM',
            'close' => '09:00 PM',
        ), 
        array( //Tuesday
            'open' => '09:00 AM',
            'close' => '09:00 PM',
        ), 
        array( //Wednesday
            'open' => '09:00 AM',
            'close' => '09:00 PM',
        ), 
        array( //Thursday
            'open' => '09:00 AM',
            'close' => '09:00 PM',
        ), 
        array( //Friday
            'open' => '09:00 AM',
            'close' => '09:00 PM',
        ),
        array( //Saturday
            'open' => '11:00 AM',
            'close' => '06:00 PM',
        ), 
    );

    $current_day = date( 'w', current_time('timestamp') ); //Numeric representation of the day (0 for Sunday, 6 for Saturday)
    $current_date = date( 'd F Y', current_time('timestamp') );

    if ( $store_times[$current_day] !== false ) {

        $opening_time = strtotime( sprintf( '%s %s', $current_date, $store_times[$current_day]['open'] ) );
        $closing_time = strtotime( sprintf( '%s %s', $current_date, $store_times[$current_day]['close'] ) );

        if ( $closing_time > current_time('timestamp') && $closing_time - current_time('timestamp') < 1800 ) {
            echo "<p 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 = minutes + "m " + seconds + "s 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  ( $opening_time > current_time('timestamp') || $closing_time < current_time('timestamp') ) {
            echo "<p>Closed for today</p>";
        } else {
            echo "<p>Open for business</p>";
        }
    } else {
        echo "<p>Closed for today</p>";
    }
}
add_action('woocommerce_archive_description'、'sat_clock');
功能卫星时钟(){
$store\u times=数组(
错,//星期天
数组(//星期一)
“开放”=>“上午09:00”,
“关闭”=>“晚上9:00”,
), 
数组(//星期二)
“开放”=>“上午09:00”,
“关闭”=>“晚上9:00”,
), 
数组(//星期三)
“开放”=>“上午09:00”,
“关闭”=>“晚上9:00”,
), 
数组(//星期四)
“开放”=>“上午09:00”,
“关闭”=>“晚上9:00”,
), 
数组(//星期五)
“开放”=>“上午09:00”,
“关闭”=>“晚上9:00”,
),
数组(//星期六)
“开放”=>“上午11:00”,
“关闭”=>“下午6:00”,
), 
);
$current_day=date('w',current_time('timestamp');//一天的数字表示(0表示周日,6表示周六)
$current_date=日期('dfy',current_time('timestamp');
如果($store\u times[$current\u day]!==false){
$opening_time=strottime(sprintf('%s%s',$current_date,$store_times[$current_day]['open']);
$closing_time=strottime(sprintf('%s%s',$current_date,$store_times[$current_day]['close']);
if($closing_time>current_time('timestamp')&&$closing_time-current_time('timestamp')小于1800){
echo“

”; ?> var timeLeft=; //每1秒更新一次倒计时 var x=setInterval(函数(){ //分钟和秒的时间计算 var分钟=数学楼层(时间限制/60); var秒=数学地板(时间间隔%60); //使用id=“demo”在元素中显示结果 document.getElementById(“即将关闭计时器”).innerHTML=minutes+“m”+seconds+“s下单。”; //如果倒计时结束,写一些文字 如果(时间间隔<0){ 净间隔(x); document.getElementById(“即将关闭计时器”).innerHTML=“今天关闭”; } 时间限制--; }, 1000);
你可能会想使用JavaScript来完成这项任务。也许可以看看:这太棒了!非常感谢!但有一个问题-这个脚本如何知道我的打开时间?它不知道。对于倒计时,你只需要当前日期和关闭时间。但是我已经更新了我的答案,所以你现在可以检查打开、关闭和几乎关闭的时间失败。如果这个答案对你有效,请将其标记为接受,并可能投票支持。