问题描述
在 Woocommerce 中,下订单后,我想在 5 秒后自动将客户从谢谢页面重定向到外部链接,传递一些变量作为 order_id
和 order_ammount代码>.
In Woocommerce, after placing an order, I Would like to redirect customer automatically after 5 sec from the thankyou page to external link passing a few variables as the order_id
, and the order_ammount
.
那么如何在 5 秒后自动将客户从 Woocommerce 谢谢重定向到传递变量的外部链接?
So How can I redirect customer automatically from Woocommerce thankyou to an external link passing variables after 5 seconds?
欢迎任何曲目.
推荐答案
以下代码将使用 php 和 javascript 从结帐页面重定向到外部链接,并在 5 秒后传递几个变量:
The following code will redirect from checkout page to an external link passing few variables after 5 seconds using php and 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 文件中.经测试有效.
Code goes in function.php file of your active child theme (or active theme). tested and works.
重定向链接就像http://example.com/path/?order_id=1420&order_ammount=136.20
这篇关于自动从 Woocommerce 重定向到传递变量的外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!