Magento 2

Magento2 How to disabled free shipping method at frontend

Magento2 How to disabled free shipping method at frontend.

In this article, I am going to show Magento2 How to disabled free shipping method at frontend.

At magento2, it difficult to disable a shipping method at frontend and Enable at admin area.

At first, I target to override  Free shipping method class  Magento\OfflineShipping\Model\Carrier\Freeshipping ‘s method  collectRates() using Plugin around method


And defined under  di.xml  at app/code/Devamitbera/CoreRewrite/etc/  and try disable by using Area code


But this is not working at Magento checkout page. I was going strange as the condition as was not working as excepted.

Then, I was started to debug and find that issue is this Magento area.At Checkout page, Magento is estimating Shipping method current quote using of   its Rest API   and that why area code at plugin is webapi_rest.

That why the condition was not working!.


So, again trying to find the solution of that issue.

  • Create a new field is_frontent_checkout at Quote table using setup install script InstallData.php  at at app/code/Devamitbera/CoreRewrite/etc/Setup and set it value to 0 or 1  and by default set value 0.

  • As I want to set it to  1 when Customer cart a product frontend that why I had fired an observer on the event   checkout_cart_save_before  and declare events.xml at app/code/Devamitbera/CoreRewrite/etc/frontend.


Observer class  AssignCurrentStoreIsFrontend.php at app/code/Devamitbera/CoreRewrite/Observer


  • Now disabling the free shipping method when that field value  1.So, I have changed in the Plugin class code.



In this logic, you can disable any shipping method.


Hope, it will help other people.

Related Post:

  1. How to get magento2 base url
  2. Magento2 redirection from Observer
  3. Magento2 get admin url


  • John Francis

    Hi Amit,

    You will remember that we could not get the featured products to be listed at $0.00 shipping when other (non-free) products were included in the cart. And if we started with the free shipping item, then the rest of the products’ shipping charges was ignored.

    The client finally asked me. “what if we set the weight to “0” lb? That did it! In fact, Magento 2 has a config item for each product asking whether the item has weight (or not). Result: zero weight means no charge in most cases. I was able to mix free shipping into any shopping cart mix and the weight of the free shipping items was ignored.

  • Athreya

    Hey Amit,
    I followed your steps, but I am unable to get the solution.I am getting confused with the plugin file. If i am including the plugin file with di.xml by overriding “Magento\OfflineShipping\Model\Carrier\Freeshipping” I am getting an error at checkout “Plugin class doesn’t exist”. If i am not keeping di.xml I am able to see checkout, but free shipping method is also coming. Please suggest me how to proceed.
    Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *