cancel
Showing results for 
Search instead for 
Did you mean: 

shipping method based on location

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

shipping method based on location

Hi Guys,

In my applicaton I have integrated UPS, GSM and free for collection based on city, region and country I want to hide and show the shipping method when the customer switching the address in checkout page. I was looking on this for so long, Can you guys please help me on this?

saranya
1 REPLY 1

Re: shipping method based on location

Hello,

 

You can use default magento table rate for same.

 

or you can use

etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Shipping\Model\Rate\Result">
        <plugin name="restrict_shippingmethod" type="[Vendor]\[Module]\Plugin\ShippingMethod" sortOrder="500" />
    </type>
</config>
<?php

namespace [Vendor]\[Module]\Plugin;

class ShippingMethod
{
    public function beforeAppend($subject, $result)
    {
        if (!$result instanceof \Magento\Quote\Model\Quote\Address\RateResult\Method) {
            return [$result];
        }

        if ($this->isMethodRestricted($result)) {
            $result->setIsDisabled(true);
        }

        return [$result];
    }

    public function isMethodRestricted($shippingModel)
    {
        $code = $shippingModel->getCarrier();
        $restrictedMethod = ['replace_method_code'];

        if ($restrictedMethod && in_array($code, $restrictedMethod)) {
            return true;
        }

        return false;
    }
}

or use amasty shipping method module

https://amasty.com/shipping-table-rates-for-magento-2.html

 

hope it will help you.

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer