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!
In the world of business, understanding financial metrics is crucial for making informed decisions and…
Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…
In this era, businesses are always on the lookout for ways to engage with their…
Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…
E-commerce has transformed the way consumers shop for products and services and interact with businesses.…
The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…
View Comments
nice article fella, it's first text like this on google.com lol