Sujan Pokhrel
Sujan Pokhrel

Reputation: 1

Redirect to new page after coupon is applied in woocommerce

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

Answers (2)

WebbyCrown Solutions
WebbyCrown Solutions

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

Jamie Robinson
Jamie Robinson

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

Related Questions