WooCommerce: Redirect to a Specific URL on Coupon Removal
Here’s a super short snippet, that someone asked a couple of days ago: how to redirect a visitor to a specific page when a coupon is removed on the cart page.
<?php // Do not include this if already open! Code goes in theme functions.php.
/*
* Redirects user to a specific page upon coupon removal.
*/
function action_woocommerce_removed_coupon( $coupon_code ) {
// Redirection...
wp_redirect( $url ); // Replace $url by your page URL.
exit;
};
// add the action
add_action(
'woocommerce_removed_coupon',
'action_woocommerce_removed_coupon',
10,
1
);
Let’s say that you need/want to display specific content to the visitors removing a coupon that is automatically applied to the cart, or something in the same vein, well, here’s how to do so!