Hello Magento Friends,
Today I will be discussing on How to Remove/Disable Custom Free Shipping Method from Front-end only in Magento 2?
Many times, you do not want to provide a free shipping method to your customers. But the orders placed from the admin grid should have a free shipping method. At that time, Magento store merchants come across the requirement to disable or remove the free shipping method from the store frontend only. Also, check out Shipping and Payment Method per Customer Group Extension which allows the store owner to manage shipping and payment method for the specific customer groups.
So, let’s find out How to Remove/Disable Custom Free Shipping Method from Front-end only in Magento 2?
Contents
Step 1: Go to the below path,
app\code\Vendor\Extension\etc\di.xml
And add this code,
<?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="Vendor\Extension\Model\Carrier\Customshipping"> <plugin name="disable_customshipping" type="Vendor\Extension\Plugin\DisableEnableCustomShipping" sortOrder="1" /> </type> </config>
Step 2: Now, go to the below path,
app\code\Vendor\Extension\Plugin\DisableEnableCustomShipping.php
And finally, add the code as mentioned below:
<?php namespace Vendor\Extension\Plugin; use Magento\Backend\Model\Auth\Session; class DisableEnableCustomShipping { /** * @var Session */ private $_session; public function __construct(Session $session) { $this->_session = $session; } public function aroundCollectRates( \Vendor\Extension\Model\Carrier\Customshipping $subject, \Closure $proceed, $request) { if (!$this->_session->isLoggedIn()) { return false; // Only allow this to be used from the admin system } $result = $proceed($request); return $result; } }
Hence, with the help of the above code, you can easily Remove/Disable Custom Free Shipping Method from Front-end only in Magento 2. Also, check out Shipping and Payment Method per Customer Group Extension which allows the store owner to manage shipping and payment method for the specific customer groups. If you have any difficulty, mention it in the comment section. Do share the article further. See you soon till then stay in touch!
Happy Coding!
Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…
If you are a Shopify admin, using a Shopify Balance Account for your business revenue…
Running an eCommerce business can be incredibly demanding, leaving entrepreneurs little time to focus on…
Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…
In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…
October was an exciting month for MageComp! From significant updates across our Magento 2 extension…
View Comments
nice article fella, it's first text like this on google.com lol