简体   繁体   English

如何每20秒刷新woocomerce结帐页面?

[英]How can i refresh woocomerce checkout page every 20 seconds?

I have a problem with a woocommerce site I have. 我的woocommerce网站有问题。

The problem is that I need to refresh the checkout page every 20 seconds when I hit the place order button. 问题是,当我按下下订单按钮时,我需要每20秒刷新一次结帐页面。

The main reason is that I have a plugin that informs in real time the user for the order. 主要原因是我有一个插件可以实时通知用户订单。 Also it process the order to be from " onhold " to " completed " automatically. 它还会自动处理从“ 保留 ”到“ 完成 ”的订单。

But for some reason in iPad - iPhones it isn't refreshing, so is there any possible solution to refresh the checkout page automatically? 但是由于iPad某些原因iPhones不能刷新,所以有没有可能的方法来自动刷新结帐页面?

This is the code I use to update the checkout status automatically: 这是我用来自动更新结帐状态的代码:

/* Reset status of new orders from "on-hold" to "complete" */
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
    global $woocommerce;
     if ( !$order_id )
        return;
    $order = new WC_Order( $order_id );
    $order->update_status( 'completed' );
}

Thanks all for your time :) 谢谢大家的时间:)

hi put below code into function.php 嗨,把下面的代码放到function.php

function reload_page( $atts ){
    if(is_checkout()) { ?>
<script type="text/javascript">
window.setTimeout(function(){ document.location.reload(true); }, 20000);
</script>
<?php }

}
add_shortcode( 'reloadpage', 'reload_page' );

and put this shortcode [reloadpage] into checkout page. 并将此短代码[reloadpage]放入结帐页面。 this will reload page after every 20sec. 每20秒就会重新加载一次页面。

hope this will work for you 希望这对你有用

I manage to make it work with the help of Corlax..So just for educational purposes...If i want to loop only one time in 20 sec, what else i have to edit in javascript? 我设法在Corlax的帮助下使其正常工作。.因此,仅出于教育目的...如果我只想在20秒内循环一次,我还需要在javascript中进行哪些编辑?

Here is the code: 这是代码:

/* Reset status of new orders from "on-hold" to "complete" */
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
    global $woocommerce;
     if ( !$order_id )
        return;
    $order = new WC_Order( $order_id );
    $order->update_status( 'completed' );


{ ?>
<script type="text/javascript">
window.setTimeout(function(){ document.location.reload(true); }, 20000);

</script>
<?php }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM