Checkout: Trigger updates on country/region changes

You can create a mixin for Magento_Checkout/js/action/set-shipping-information and use that to add an event listener to the shipping address select fields (or any other field for that matter).

Under you theme root folder create a requirejs-config.js file declaring the mixin

#File: Theme_Vendor/Theme_Name/requirejs-config.js

var config = {
    'config': {
        'mixins': {
            'Magento_Checkout/js/action/set-shipping-information': {
                'Magento_Checkout/js/action/set-shipping-information-mixin': true
            } 
        }
    }
};

The create the mixin file set-shipping-information-mixin.js under the declared Theme_Vendor/Theme_Name/Magento_Checkout/js/action folder with the following content:

define([
    'jquery',
    /*'mage/utils/wrapper',
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/model/cart/totals-processor/default',
    'Magento_Checkout/js/model/shipping-service',
    'Magento_Checkout/js/model/shipping-rate-registry',
    'Magento_Checkout/js/model/shipping-rate-processor/customer-address',
    'Magento_Checkout/js/model/shipping-rate-processor/new-address',*/
], function ($ /*, wrapper, quote, totalsDefaultProvider, shippingService, rateRegistry, customerAddressProcessor, newAddressProcessor*/) {

    $(document).on('change',"[name='country_id']",function(){
       // Add functionality here for country change
    });

    $(document).on('change',"[name='region_id']",function(){
       // Add functionality here for region change
    });    

    return function (target) {
        return target;
    };
});

Leave a Reply

Your email address will not be published. Required fields are marked *