在 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 文件中。经过测试并有效。
重定向链接就好像http://example.com/path/?order_id=1420&order_ammount=136.20
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)