Reputation: 1
I want to redirect my cart/checkout page to new page if coupon is applied in woocommerce. I have a coupon for free print. If user applies it, I want the page to be redirected to a new page where user are given some products to choose. I'm having great trouble to redirect the page after the coupon has been applied. Any problemm would be greatly appriciated.
Thanks
Upvotes: 0
Views: 1644
Reputation: 11
The following hook fires after a coupon has been applied to the cart. You can place the code in functions.php
of the theme.
add_action( 'woocommerce_applied_coupon', 'action_redirect_to_page_after_applied_coupon' );
function action_redirect_to_page_after_applied_coupon( $coupon_code ){
// Redirect to url
wp_redirect( $url ); // Replace $url by your page URL.
exit;
}
The following code gives the ability to redirect a user after removing a coupon. You can place the code in functions.php
of the theme.
function action_redirect_to_page_after_removed_coupon( $coupon_code ) {
// Redirect to url
wp_redirect( $url ); // Replace $url by your page URL.
exit;
};
add_action( 'woocommerce_removed_coupon', 'action_redirect_to_page_after_removed_coupon', 10, 1 );
Upvotes: 1
Reputation: 868
This is a javascript redirect with can be deployed anywhere in your php code
echo("<script> window.location = www.youradress.co.uk </script>");
For interest sake, this doesn't always work as if someone turns off their java (unlikely) it won't call, so you can use this which is a native php redirect
header("location:www.youradress.co.uk");
This has to be called before any html is created, including comments though :)
Upvotes: -2