Update Shipping Methods on Checkout with Zipcode Change – Magento 2

magento2shipping-methodszipcode

How can I update shipping methods on checkout with changes in zipcode input?

My shipping methods are not updating with zipcode input change value. Only with page refresh.

Best Answer

I fix that editing this function on shipping.js:

               checkoutProvider.on('shippingAddress', function (shippingAddressData) {
                    /* Custom code to update shipping rates init */
                    if(s_postcode == null){
                        s_postcode = shippingAddressData.postcode;
                    }else{
                        if(shippingAddressData.postcode != s_postcode && shippingAddressData.postcode.length == 9){

                     checkoutDataResolver.resolveEstimationAddress();
                        }else{
                            if(s_postcode != null){
                                shippingAddressData.postcode = s_postcode;
                            }
                        }
                    }
                    /* Custom code to update shipping rates init */
                    checkoutData.setShippingAddressFromData(shippingAddressData);
                });

and declarate var:

var s_postcode = null;
Related Topic