简体   繁体   中英

How can i refresh woocomerce checkout page every 20 seconds?

I have a problem with a woocommerce site I have.

The problem is that I need to refresh the checkout page every 20 seconds when I hit the place order button.

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?

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 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. this will reload page after every 20sec.

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?

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 }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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