0

Is there any way I can check for specific store id & based on that prevent shipping method to be displayed?

1
  • any thoughts on this ?
    – devhs
    Jun 25, 2021 at 9:18

1 Answer 1

0

Create 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\Quote\Api\ShipmentEstimationInterface">
        <plugin name="hide_show_shipping_methods" type="Vendor\Module\Plugin\Quote\Api\ShipmentEstimationPlugin"/>
    </type>
</config>

Create Vendor\Module\Plugin\Quote\Api\ShipmentEstimationPlugin.php.

<?php

namespace Vendor\Module\Plugin\Quote\Api;

use Magento\Quote\Api\ShipmentEstimationInterface;

class ShipmentEstimationPlugin
{
    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager, 
    ) {
        $this->_storeManager = $storeManager;
    }

    public function aroundEstimateByExtendedAddress(
        ShipmentEstimationInterface $subject,
        \Closure $proceed,
        $cartId,
        \Magento\Quote\Api\Data\AddressInterface $address
    ) {
        $shippingMethods = $proceed($cartId, $address);
        if ($this->_storeManager->getStore()->getId() == "<store_id>") {
            foreach ($shippingMethods as $key => $shippingMethod) {
                //Replace 'freeshipping' with your shipping method which you want to hide
                if ($shippingMethod->getMethodCode() == 'freeshipping') {
                    unset($shippingMethods[$key]);
                }
            }

            return $shippingMethods;
        }
    }
}

It will work for you.

This is a modification of this post as it work for me

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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