Javascript 自动重定向到传递变量的外部链接
在Woocommerce中,下单后,我想在5秒钟后自动将客户从thankyou页面重定向到外部链接,并传递一些变量,如Javascript 自动重定向到传递变量的外部链接,javascript,php,wordpress,woocommerce,orders,Javascript,Php,Wordpress,Woocommerce,Orders,在Woocommerce中,下单后,我想在5秒钟后自动将客户从thankyou页面重定向到外部链接,并传递一些变量,如订单id,以及订单金额 那个么,我如何在5秒钟后将客户从Woocommerce thankyou自动重定向到传递变量的外部链接 欢迎任何跟踪。以下代码将从签出页面重定向到外部链接,并在5秒钟后使用php和javascript传递几个变量: add_action( 'woocommerce_thankyou', 'thankyou_delated_external_redirec
订单id
,以及订单金额
那个么,我如何在5秒钟后将客户从Woocommerce thankyou自动重定向到传递变量的外部链接
欢迎任何跟踪。以下代码将从签出页面重定向到外部链接,并在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;
}
add_action('woocommerce_thankyou','thankyou_delated_external_redirection',10,1);
函数Thankyu\u delated\u外部\u重定向($order\u id){
如果(!$order\u id){
返回;
}
$order=wc\u get\u order($order\u id);//wc\u order对象的实例
$order\u total=$order->get\u total();//订单总额
$link\uhttp://www.example.com/“;//基本url
$link\u redirect.='?order\u id='.$order\u id.&order\u amount='.$order\u total;//传递的变量
?>
jQuery(函数($){
//以5秒的延迟重定向
setTimeout(函数(){
window.location.href='';
}, 5000);
});
查看类似的案例