Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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
Javascript 在WooCommerce单一产品页面上产品销售结束前的倒计时_Javascript_Php_Wordpress_Woocommerce_Countdown - Fatal编程技术网

Javascript 在WooCommerce单一产品页面上产品销售结束前的倒计时

Javascript 在WooCommerce单一产品页面上产品销售结束前的倒计时,javascript,php,wordpress,woocommerce,countdown,Javascript,Php,Wordpress,Woocommerce,Countdown,正如我正在学习的那样,我的目标是在产品页面上的add to cart表单之后添加一个倒计时计时器,它将倒计时到销售结束为止 我正在使用w3schools网站上的“”,我编写了代码,使用$sale\u date=get\u post\u meta($product->get\u id(),'u sale\u price\u dates\u to',true)将\u sale\u dates\u转换为 我的问题是: 产品页面上没有显示任何内容。没有通知,没有错误,错误日志中没有任何内容。我相信这就是

正如我正在学习的那样,我的目标是在产品页面上的add to cart表单之后添加一个倒计时计时器,它将倒计时到销售结束为止

我正在使用w3schools网站上的“”,我编写了代码,使用
$sale\u date=get\u post\u meta($product->get\u id(),'u sale\u price\u dates\u to',true)将
\u sale\u dates\u转换为

我的问题是: 产品页面上没有显示任何内容。没有通知,没有错误,错误日志中没有任何内容。我相信这就是问题所在,但我不确定:
var countDownDate=

到目前为止的代码:

add_action( 'woocommerce_after_add_to_cart_form', 'sales_timer_countdown_product', 20 );
function sales_timer_countdown_product() {  

    global $product;

    $sale_date = get_post_meta( $product->get_id(), '_sale_price_dates_to', true );
        if (!empty( $sale_date ) ) { ?>

    <script>
        // Set the date we're counting down to
        var countDownDate = <?php $sale_date; ?>

        // Update the count down every 1 second
        var x = setInterval(function() {

        // Get today's date and time
        var now = new Date().getTime();
            
        // Find the distance between now and the count down date
        var distance = countDownDate - now;
            
        // Time calculations for days, hours, minutes and seconds
        var days = Math.floor(distance / (1000 * 60 * 60 * 24));
        var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((distance % (1000 * 60)) / 1000);
            
        // Output the result in an element with id="saleend"
        document.getElementById("saleend").innerHTML = days + "d " + hours + "h "
        + minutes + "m " + seconds + "s ";
            
        // If the count down is over, write some text 
        if (distance < 0) {
            clearInterval(x);
            document.getElementById("saleend").innerHTML = "The sale for this product has EXPIRED";
        }
        }, 1000);
    </script>

    <!-- this is where the countdown is displayed -->
    <p id="saleend" style="color:red"></p>
    <?php
    }
}
add_action('woocommerce_后添加_至_cart_表单','sales_timer_倒计时_product',20);
函数sales\u timer\u countdown\u product(){
全球$产品;
$sale\u date=get\u post\u meta($product->get\u id(),'u sale\u price\u dates\u to',true);
如果(!空($sale_date)){?>
//确定我们倒计时的日期
var倒计时日期=
//每1秒更新一次倒计时
var x=setInterval(函数(){
//获取今天的日期和时间
var now=new Date().getTime();
//找出现在和倒计时日期之间的距离
var距离=倒计时日期-现在;
//天、小时、分钟和秒的时间计算
变量天数=数学楼层(距离/(1000*60*60*24));
可变小时数=数学楼层((距离%(1000*60*60*24))/(1000*60*60));
var分钟=数学楼层((距离%(1000*60*60))/(1000*60));
var秒=数学楼层((距离%(1000*60))/1000);
//在id=“saleend”的元素中输出结果
document.getElementById(“saleend”).innerHTML=days+“d”+hours+“h”
+分钟+米+秒+秒;
//如果倒计时结束,写一些文字
如果(距离<0){
净间隔(x);
document.getElementById(“saleend”).innerHTML=“此产品的销售已过期”;
}
}, 1000);


乘以1000,因为
Date()
需要毫秒

function sales\u timer\u countdown\u product(){
全球$产品;
$sale\u date=get\u post\u meta($product->get\u id(),'u sale\u price\u dates\u to',true);
如果(!空($sale_date)){
?>
//确定我们倒计时的日期
var countDownDate=*1000;
//每1秒更新一次倒计时
var x=setInterval(函数(){
//获取今天的日期和时间
var now=new Date().getTime();
//找出现在和倒计时日期之间的距离
var距离=倒计时日期-现在;
//天、小时、分钟和秒的时间计算
变量天数=数学楼层(距离/(1000*60*60*24));
可变小时数=数学楼层((距离%(1000*60*60*24))/(1000*60*60));
var分钟=数学楼层((距离%(1000*60*60))/(1000*60));
var秒=数学楼层((距离%(1000*60))/1000);
//在id=“saleend”的元素中输出结果
document.getElementById(“saleend”).innerHTML=days+“d”+hours+“h”+minutes+“m”+seconds+“s”;
//如果倒计时结束,写一些文字
如果(距离<0){
净间隔(x);
document.getElementById(“saleend”).innerHTML=“此产品的销售已过期”;
}
}, 1000);


乘以1000,因为
Date()
需要毫秒

function sales\u timer\u countdown\u product(){
全球$产品;
$sale\u date=get\u post\u meta($product->get\u id(),'u sale\u price\u dates\u to',true);
如果(!空($sale_date)){
?>
//确定我们倒计时的日期
var countDownDate=*1000;
//每1秒更新一次倒计时
var x=setInterval(函数(){
//获取今天的日期和时间
var now=new Date().getTime();
//找出现在和倒计时日期之间的距离
var距离=倒计时日期-现在;
//天、小时、分钟和秒的时间计算
变量天数=数学楼层(距离/(1000*60*60*24));
可变小时数=数学楼层((距离%(1000*60*60*24))/(1000*60*60));
var分钟=数学楼层((距离%(1000*60*60))/(1000*60));
var秒=数学楼层((距离%(1000*60))/1000);
//在id=“saleend”的元素中输出结果
document.getElementById(“saleend”).innerHTML=days+“d”+hours+“h”+minutes+“m”+seconds+“s”;
//如果倒计时结束,写一些文字
如果(距离<0){
净间隔(x);
document.getElementById(“saleend”).innerHTML=“此产品的销售已过期”;
}
}, 1000);