2

I'm using DHL Shipping Method. I have set Show Method if Not Applicable to Yes.

Displayed Error Message will be displayed, when it's applicable.

I would like to show this Error Message by Specific Country.

Example: If it's Singapore then this message will be not displayed. For other countries, it will be displayed.

0

Below is the solution

magento\app\code\Custom\Checkout\view\frontend\requirejs-config.js

var config = {
  "map": {
    "*": {
      "Magento_Checkout/js/model/shipping-service" : "Custom_Checkout/js/model/shipping-service"
    }
  }
};

magento\app\code\Custom\Checkout\view\frontend\web\js\model\shipping-service.js

/*global define*/
define(
        [
            'jquery', // For jQuery Added
            'Magento_Checkout/js/model/quote', // For Quote Added
            'ko',
            'Magento_Checkout/js/model/checkout-data-resolver'
        ],
        function ($, quote, ko, checkoutDataResolver) {
            "use strict";
            var shippingRates = ko.observableArray([]);
            return {
                isLoading: ko.observable(false),
                /**
                 * Set shipping rates
                 *
                 * @param ratesData
                 */
                setShippingRates: function (ratesData) {

                   // START TO REMOVE ERROR MESSAGE FOR DHL IF SG
                    var address = quote.shippingAddress();

                    $.each(ratesData, function (k, v) {
                        if(v.method_code == null && v.carrier_code == 'dhl' && v.error_message != '' && address.countryId == 'SG'){
                            ratesData.splice(k , 1);
                        }
                    });
                    // STOP TO REMOVE ERROR MESSAGE FOR DHL IF SG

                    shippingRates(ratesData);
                    shippingRates.valueHasMutated();
                    checkoutDataResolver.resolveShippingRates(ratesData);
                },

                /**
                 * Get shipping rates
                 *
                 * @returns {*}
                 */
                getShippingRates: function () {
                    return shippingRates;
                }
            };
        }
);

If someone has solution on PHP side then it would be great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.