自动从 Woocommerce 重定向到外部 link 传递变量

Redirect automatically from Woocommerce thankyou to an external link passing variables

在 Woocommerce 中,下订单后,我想在 5 秒后自动将客户从感谢页面重定向到外部 link,传递一些变量作为 order_idorder_ammount.

那么如何在 5 秒后自动将客户从 Woocommerce 谢谢重定向到外部 link 传递变量?

欢迎任何曲目。

以下代码将从结帐页面重定向到外部 link 在 5 秒后使用 php 和 javascript 传递几个变量:

 add_action( 'woocommerce_thankyou', 'thankyou_delated_external_redirection', 10, 1 );
function thankyou_delated_external_redirection( $order_id ){
    if( ! $order_id ){
        return;
    }

    $order          = wc_get_order( $order_id ); // Instannce of the WC_Order Object
    $order_total    = $order->get_total(); // Order total amount

    $link_redirect  = 'http://www.example.com/'; // Base url
    $link_redirect .= '?order_id='.$order_id.'&order_ammount='.$order_total; // passed variables

    ?>
    <script>
    jQuery(function($){
        // Redirect with a delay of 5 seconds
        setTimeout(function(){
            window.location.href = '<?php echo $link_redirect; ?>';
        }, 5000);
    });
    </script>
    <?php;
}

代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。

The redirection link is like http://example.com/path/?order_id=1420&order_ammount=136.20