@@ -246,7 +246,7 @@ define([
246
246
name ,
247
247
data ,
248
248
resetShipping = false ,
249
- resetBilling = false ;
249
+ resetSelectedBillingAddress = false ;
250
250
251
251
if ( ! matchRes ) {
252
252
return ;
@@ -265,15 +265,15 @@ define([
265
265
if ( type === 'billing' && this . shippingAsBilling ) {
266
266
this . syncAddressField ( this . shippingAddressContainer , field . name , field ) ;
267
267
resetShipping = true ;
268
- resetBilling = true ;
268
+ resetSelectedBillingAddress = true ;
269
269
}
270
270
271
271
if ( type === 'shipping' && ! this . shippingAsBilling ) {
272
272
resetShipping = true ;
273
273
}
274
274
275
275
if ( type === 'billing' && ! this . shippingAsBilling ) {
276
- resetBilling = true ;
276
+ resetSelectedBillingAddress = true ;
277
277
}
278
278
279
279
if ( resetShipping ) {
@@ -284,7 +284,7 @@ define([
284
284
}
285
285
}
286
286
287
- if ( resetBilling ) {
287
+ if ( resetSelectedBillingAddress ) {
288
288
if ( name !== 'customer_address_id' && this . selectAddressEvent === false ) {
289
289
this . clearSelected ( 'order-billing_address_customer_address_id' ) ;
290
290
}
@@ -297,9 +297,10 @@ define([
297
297
data [ 'order[' + type + '_address][customer_address_id]' ] =
298
298
$ ( 'order-' + type + '_address_customer_address_id' ) . value ;
299
299
300
+ // Clear previously selected shipping address id in order to treat it as new from frontend
301
+ // dropdown(Select from existing customer addresses) change event
300
302
if ( this . shippingAsBilling ) {
301
- document . getElementById ( 'order-shipping_address_customer_address_id' ) . value =
302
- $ ( 'order-' + type + '_address_customer_address_id' ) . value ;
303
+ this . clearSelected ( 'order-shipping_address_customer_address_id' ) ;
303
304
}
304
305
}
305
306
@@ -326,11 +327,11 @@ define([
326
327
* @param {String } id - field ID
327
328
*/
328
329
clearSelected : function ( id ) {
329
- let element = document . getElementById ( id ) ;
330
+ var element = $ ( id ) ;
330
331
if ( typeof element !== 'undefined' && element !== null ) {
331
332
if ( element . value ) {
332
- let elem = element . options ;
333
- for ( let i = 0 ; i < elem . length ; i ++ ) {
333
+ var elem = element . options ;
334
+ for ( var i = 0 ; i < elem . length ; i ++ ) {
334
335
elem [ i ] . selected = false ;
335
336
}
336
337
}
@@ -456,6 +457,9 @@ define([
456
457
data = data . toObject ( ) ;
457
458
data [ 'shipping_as_billing' ] = flag ? 1 : 0 ;
458
459
data [ 'reset_shipping' ] = 1 ;
460
+ // set customer_address_id to null for shipping address in order to treat it as new from backend
461
+ // Checkbox(Same As Billing Address) uncheck event
462
+ data [ 'order[shipping_address][customer_address_id]' ] = null ;
459
463
this . loadArea ( areasToLoad , true , data ) ;
460
464
} ,
461
465
0 commit comments