@@ -135,8 +135,8 @@ jQuery( function ( $ ) {
135
135
if ( $ ( '.woocommerce-checkout' ) . length ) {
136
136
$ ( document . body ) . trigger ( 'update_checkout' ) ;
137
137
}
138
-
139
- // Store the old coupon error message and value before the
138
+
139
+ // Store the old coupon error message and value before the
140
140
// .woocommerce-cart-form is replaced with the new form.
141
141
var $old_coupon_field_val = $ ( '#coupon_code' ) . val ( ) ;
142
142
var $old_coupon_error_msg = $ ( '#coupon_code' )
@@ -151,7 +151,7 @@ jQuery( function ( $ ) {
151
151
if ( preserve_notices && $old_coupon_error_msg . length > 0 ) {
152
152
var $new_coupon_field = $ ( '.woocommerce-cart-form' ) . find ( '#coupon_code' ) ;
153
153
var $new_coupon_field_wrapper = $new_coupon_field . closest ( '.coupon' ) ;
154
-
154
+
155
155
$new_coupon_field . val ( $old_coupon_field_val ) ;
156
156
// The coupon input with error needs to be focused before adding the live region
157
157
// with the error message, otherwise the screen reader won't read it.
@@ -206,30 +206,32 @@ jQuery( function ( $ ) {
206
206
return ;
207
207
}
208
208
209
- var $coupon_error_el = '' ;
209
+ var $coupon_error_el = html_element ;
210
210
211
211
if ( typeof html_element === 'string' ) {
212
212
var msg = $ ( $ . parseHTML ( html_element ) ) . text ( ) . trim ( ) ;
213
-
213
+
214
214
if ( msg === '' ) {
215
215
return ;
216
216
}
217
-
218
- $coupon_error_el = $ ( '<p class="coupon-error-notice" id="coupon-error-notice">' + msg + '</p>' ) ;
219
- } else {
220
- $coupon_error_el = html_element ;
217
+
218
+ $coupon_error_el = $ ( '<p>' , {
219
+ class : 'coupon-error-notice' ,
220
+ id : 'coupon-error-notice' ,
221
+ text : msg
222
+ } ) ;
221
223
}
222
224
223
225
if ( is_live_region ) {
224
226
$coupon_error_el . attr ( 'role' , 'alert' ) ;
225
227
}
226
-
228
+
227
229
$target . find ( '#coupon_code' )
228
230
. addClass ( 'has-error' )
229
231
. attr ( 'aria-invalid' , 'true' )
230
232
. attr ( 'aria-describedby' , 'coupon-error-notice' ) ;
231
233
$target . append ( $coupon_error_el ) ;
232
- } ;
234
+ } ;
233
235
234
236
/**
235
237
* Object to handle AJAX calls for cart shipping changes.
@@ -280,7 +282,7 @@ jQuery( function ( $ ) {
280
282
$target . attr ( 'aria-expanded' , $form . is ( ':visible' ) ? 'true' : 'false' ) ;
281
283
} , 0 ) ;
282
284
} ) ;
283
-
285
+
284
286
$ ( 'select.country_to_state, input.country_to_state' ) . trigger (
285
287
'change'
286
288
) ;
@@ -315,7 +317,7 @@ jQuery( function ( $ ) {
315
317
dataType : 'html' ,
316
318
success : function ( response ) {
317
319
update_cart_totals_div ( response ) ;
318
-
320
+
319
321
var newCurrentTarget = document . getElementById ( event . currentTarget . id ) ;
320
322
321
323
if ( newCurrentTarget ) {
@@ -600,17 +602,17 @@ jQuery( function ( $ ) {
600
602
'.woocommerce-error, .woocommerce-message, .woocommerce-info, ' +
601
603
'.is-error, .is-info, .is-success, .coupon-error-notice'
602
604
) . remove ( ) ;
603
-
605
+
604
606
// We only want to show coupon notices if they are not errors.
605
607
// Coupon errors are shown under the input.
606
608
if ( response . indexOf ( 'woocommerce-error' ) === - 1 && response . indexOf ( 'is-error' ) === - 1 ) {
607
- show_notice ( response ) ;
609
+ show_notice ( response ) ;
608
610
} else {
609
611
var $coupon_wrapper = $text_field . closest ( '.coupon' ) ;
610
612
611
613
if ( $coupon_wrapper . length > 0 ) {
612
614
show_coupon_error ( response , $coupon_wrapper , false ) ;
613
- }
615
+ }
614
616
}
615
617
616
618
$ ( document . body ) . trigger ( 'applied_coupon' , [
0 commit comments