在 Woocommerce 中,下订单后,我想在 5 秒后自动将客户从感谢页面重定向到外部链接,并传递一些变量作为 order_id
和 order_ammount
.
那么,如何在 5 秒后自动将客户从 Woocommerce 谢谢重定向到传递变量的外部链接?
欢迎任何轨道。
最佳答案
以下代码将使用 php 和 javascript 从结帐页面重定向到外部链接,并在 5 秒后传递一些变量:
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
关于javascript - 自动从 Woocommerce 谢谢重定向到传递变量的外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55172245/