0

I recently upgraded to Magento 2.2.1 and there are 3 products that I make and sell. I recently set up free shipping for any orders over $500. However, for these 3 products, I need to remove the free shipping. Is there a way you can do this in Magento 2 or do I need an extension to do this?

2

Assume that you have to manage free shipping using Magento Free Shipping Method Not using Cart rules.

Create a Plugin in Magento\OfflineShipping\Model\Carrier\Freeshipping and Create around plugin on aroundCollectRates and restrict the freehsipping on Product Sku.

<?php


namespace StackExchanges\OnlyMagento\Plugin\Magento\OfflineShipping\Model;

class FreeshippingPlugin {
    public function aroundCollectRates(
        \Magento\OfflineShipping\Model\Carrier\Freeshipping $subject,
        \Closure $proceed,
        \Magento\Quote\Model\Quote\Address\RateRequest $request
    ){
        $disableskus = ['sku1','sku2','sku3'];

        if (!$subject->getConfigFlag('active')) {
            return false;
        }
        $items = $request->getAllItems();
        $hasrestricProduct = false;
        foreach($items as $item)
        {
            $item->getProduct()->getSku();
            if(in_array($item->getProduct()->getSku(), $disableskus)){
                $hasrestricProduct = true;
            }
        }
        if($hasrestricProduct){
             return false;
        }
        return $proceed($request);
    }  
}
4
  • Appreciate your efforts to be perfect moderator !!! – anonymous Dec 18 '18 at 8:34
  • So I would copy this and add my SKU's in place of this line, right? $disableskus = ['sku1','sku2','sku3']; – Jeremy Myrtle Dec 18 '18 at 12:53
  • Yes, you are right – Amit Bera Dec 18 '18 at 12:59
  • So is this supposed to be a separate file, or am I editing a current file? If there is a separate file, I'm not sure where to save it. – Jeremy Myrtle Dec 18 '18 at 13:01

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.