Commit c75ccbe6fcb for woocommerce
commit c75ccbe6fcbd48029dba675f6740088121324782
Author: Faisal Ahammad <faisalahammad24@gmail.com>
Date: Fri Aug 21 14:27:24 2026 +0600
Add errored_coupon and errored_coupon_in_checkout JS events (#66285)
* Add coupon_error and coupon_error_in_checkout JS events
Fires a coupon_error event on the cart page and coupon_error_in_checkout
on the checkout page when a coupon fails to apply, using the same error
detection the AJAX handlers already run for the inline notice. Both
events pass the coupon code and the raw AJAX response so extensions can
react to a failed apply without re-implementing the error check.
Closes #59489
* fix(checkout): rename coupon error events to errored_coupon
- Rename coupon_error to errored_coupon and coupon_error_in_checkout to
errored_coupon_in_checkout to match applied_coupon convention
- Remove e2e assertions for event presence per review
Addresses PR feedback.
Refs #66285
diff --git a/plugins/woocommerce/changelog/wooplug-59489-coupon-error-event b/plugins/woocommerce/changelog/wooplug-59489-coupon-error-event
new file mode 100644
index 00000000000..01429c2355e
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-59489-coupon-error-event
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add errored_coupon and errored_coupon_in_checkout JS events fired when a coupon fails to apply on the classic cart and checkout pages.
diff --git a/plugins/woocommerce/client/legacy/js/frontend/cart.js b/plugins/woocommerce/client/legacy/js/frontend/cart.js
index 8f9a7fbd028..f704eeaa5c3 100644
--- a/plugins/woocommerce/client/legacy/js/frontend/cart.js
+++ b/plugins/woocommerce/client/legacy/js/frontend/cart.js
@@ -642,6 +642,11 @@ jQuery( function ( $ ) {
if ( $coupon_wrapper.length > 0 ) {
show_coupon_error( response, $coupon_wrapper, false );
}
+
+ $( document.body ).trigger( 'errored_coupon', [
+ coupon_code,
+ response,
+ ] );
}
$( document.body ).trigger( 'applied_coupon', [
diff --git a/plugins/woocommerce/client/legacy/js/frontend/checkout.js b/plugins/woocommerce/client/legacy/js/frontend/checkout.js
index 052c7033acb..88c6e1607f5 100644
--- a/plugins/woocommerce/client/legacy/js/frontend/checkout.js
+++ b/plugins/woocommerce/client/legacy/js/frontend/checkout.js
@@ -1294,6 +1294,11 @@ jQuery( function ( $ ) {
response,
$coupon_field.parent()
);
+
+ $( document.body ).trigger(
+ 'errored_coupon_in_checkout',
+ [ data.coupon_code, response ]
+ );
}
$( document.body ).trigger(