Magento 2 checkout - Update shipping methods after change of city, address line and telephone fields
When we need to trigger the call that updates the shipping methods on the checkout page when the city, address lines, telephone and email fields change. Just like when the shipping methods are updated when the postcode, country and province fields change.
We need to try below steps in custom shipping module as described follows and its working fine for me:
Pawan/Customshipping/view/frontend/requirejs-config.js
var config = {
"map": {
"*": {
"Magento_OfflineShipping/js/model/shipping-rates-validation-rules/flatrate": "Pawan_Customshipping/js/model/shipping-rates-validation-rules/flatrate",
}
}
};
Pawan/Customshipping/view/frontend/web/js/model/shipping-rates-validation-rules/flatrate.js
define([], function () {
'use strict';
return {
/**
* @return {Object}
*/
getRules: function () {
return {
'country_id': {
'required': true
},
'city': {
'required': true
},
'telephone': {
'required': true
}
};
}
};
});
These rules will automatically applied on change event of telephone and city fields.
I tried for flat-rate Offline shipping methods only. If you wan to do it for other shipping methods, then you can try in the same way.
Comments
Post a Comment