'Allow users to remove auto applied coupons programatically (WooCommerce)
I've added a code to auto apply coupon (Coupon name - new10) in cart and checkout page. Its working perfectly fine but when I click on "remove", it doesn't remove the coupon and auto apply the coupon again.
On the checkout page, I'm able to remove this coupon but I'm facing this issue on the cart page. Please tell me how can I allow the users to remove this coupon by clicking "remove" on the cart page.
Following is my code I've used :
add_action( 'woocommerce_before_checkout_form', 'auto_apply_coupon' );
function auto_apply_coupon() {
$coupon_code = 'new10';
if ( WC()->cart->has_discount( $coupon_code ) ) return;
WC()->cart->apply_coupon( $coupon_code );
wc_print_notices();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
