@@ -128,7 +128,7 @@ protected function addNewAddressFields(FAPI\Form $form, array &$form_state) : FA
128128 );
129129
130130 $ form
131- ->addMarkup ('<div class="row mt-3"> ' )
131+ ->addMarkup ('<div id="add-address-container" class="row mt-3"> ' )
132132 ->addField ('first_name ' , [
133133 'type ' => 'textfield ' ,
134134 'title ' => 'First Name ' ,
@@ -205,6 +205,31 @@ protected function addNewAddressFields(FAPI\Form $form, array &$form_state) : FA
205205 ])
206206 ->addMarkup ('</div> ' );
207207
208+ $ form ->addJs ("
209+ \$('input,textarea,select', '#add-address-container').on('change', function(evt) {
210+ if ( \$('#refresh_methods-event-loading').length > 0) {
211+ return;
212+ }
213+ if (['first_name','last_name','company','phone','email'].includes( \$(evt.target).attr('id'))) {
214+ return;
215+ }
216+
217+ if ( \$('#postcode', '#add-address-container').val() == '' || \$('#country_code', '#add-address-container').val() == '') {
218+ return;
219+ }
220+
221+ \$('#copy_address').val('');
222+
223+ \$('#refresh_methods').trigger('click');
224+ });
225+
226+ \$('#copy_address').on('change', function(evt) {
227+ \$('input,textarea,select', '#add-address-container').val('');
228+ \$('#refresh_methods').trigger('click');
229+ });
230+ " );
231+
232+
208233 return $ form ;
209234 }
210235
@@ -261,8 +286,9 @@ protected function addShippingMethodsAccordion(FAPI\Form $form, array &$form_sta
261286 }
262287
263288 // set cart shipping address with "temporary" data in order to get methods informations
264- $ this ->getCart ()->setShippingAddress ($ checkAddress );
265-
289+ if (!is_null ($ checkAddress )) {
290+ $ this ->getCart ()->setShippingAddress ($ checkAddress );
291+ }
266292
267293 if ($ checkAddress ) {
268294 $ methodsWithCost = array_map (function (ShippingMethodInterface $ shippingMethod ) {
@@ -303,7 +329,6 @@ protected function addShippingMethodsAccordion(FAPI\Form $form, array &$form_sta
303329 'type ' => 'hidden ' ,
304330 'default_value ' => $ this ->getShippingMethods () ? $ this ->getShippingMethodCode ($ shippingMethods [$ accordion ->getActive ()]) : '' ,
305331 ]);
306-
307332 }
308333
309334 $ form ->addField ('refresh_methods ' , [
0 commit comments