In Woocommerce, is there any way trigger JS after applied coupon like this?
I would like to use it in something like this:
$( document.body ).on( 'updated_cart_totals', function(){
//do something
});
Any help is appreciated.
You can use applied_coupon
delegated event like in this example that will display an alert box with the applied coupon code (where the variable coupon
is the applied coupon code):
<script type="text/javascript">
jQuery(function($){
$( "body" ).on( 'applied_coupon', function(event, coupon){
// Example: Displaying an alert message with the applied coupon code
alert('Applied coupon code: "' + coupon + '"\n' + 'Event type: "' + event.type + '"');
});
});
</script>
Tested and works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With