We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Create a custom module and follow the below step.

    1. Create file di.xml on app/code/Vendor/Module/etc

    <?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="MagentoOfflinePaymentsModelCashondelivery">
            <plugin name="restrict_payment_on_shippingmethod" type="VendorModulePluginMethodList" disabled="false" sortOrder="10"/>
        </type>
    </config>

    2. Create file MethodList.php on app/code/Vendor/Module/Plugin

    <?php 
    namespace VendorModulePlugin;
     
    use MagentoPaymentModelMethodAbstractMethod;
    use MagentoQuoteModelQuote;
    
    class MethodList
    {  
        public function __construct(
            PsrLogLoggerInterface $logger,
            MagentoCheckoutModelSession $checkoutSession
        ) {
            $this->logger = $logger;
            $this->_checkoutSession = $checkoutSession;
        }
    
        public function aroundIsAvailable(
          MagentoPaymentModelMethodAbstractMethod $subject, callable $proceed)
        {
            $shippingMethod = $this->_checkoutSession->getQuote()->getShippingAddress()->getShippingMethod();
            // $this->logger->debug($shippingMethod);
    
            if ($shippingMethod == 'freeshipping_freeshipping')
                return false;
    
            return $proceed();
        }
    } ?>

     

    field_5bfb909c5ccae

      Get a Free Quote