Reputation: 43
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
.
So How can I redirect customer automatically from Woocommerce thankyou to an external link passing variables after 5 seconds?
Any track is welcome.
Upvotes: 2
Views: 1455
Reputation: 253868
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;
}
Code goes in function.php file of your active child theme (or active theme). tested and works.
The redirection link is like
http://example.com/path/?order_id=1420&order_ammount=136.20
Upvotes: 2