How can I detect that Remove button/link clicked to remove the coupon from the checkout page in woocommerce.
Asked
Active
Viewed 2,365 times
1 Answers
2
You can use jQuery to live detect when "remove coupon" is clicked this way:
add_action( 'wp_footer', 'coupon_removed_script' );
function coupon_removed_script() {
if( is_cart() || ( is_checkout() && ! is_wc_endpoint_url() ) ):
?>
<script type="text/javascript">
jQuery(function($){
$('a.woocommerce-remove-coupon').on( 'click', function(){
console.log('click remove coupon');
alert('click remove coupon');
});
})
</script>
<?php
endif;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
And you can also use the following code to do something when coupon is removed (where $coupon_code
is the removed coupon code argument):
add_action("woocommerce_removed_coupon", 'coupon_removed_action');
function coupon_removed_action( $coupon_code ) {
// Do something
}
Code goes in function.php file of your active child theme (or active theme).

LoicTheAztec
- 229,944
- 23
- 356
- 399
-
thanks for your reply but the code is not working for me. – Sushil Aug 25 '18 at 07:23
-
@Sushil You should give me a live link and a coupon code to see, as your theme seems to be custom… If not you need to replace `'a.woocommerce-remove-coupon'` by the right tag class related to that button, to make the code work. – LoicTheAztec Aug 25 '18 at 07:43
-
[Bagdara Farms](https://bagdarafarms.com/demo-site-test/shop) and the code is `tester` – Sushil Aug 25 '18 at 10:55
-
@Sushil I have visit your web site and `'a.woocommerce-remove-coupon'` is just fine, **but it doesn't work because there is multiple javascript errors actually on checkout page** *(and also in cart page)*… – LoicTheAztec Aug 25 '18 at 23:00