We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
- Home
- Blog
- eCommerce Talk
- How to Remove/Disable Custom Free Shipping Method from Front-end in Magento 2?
How to Remove/Disable Custom Free Shipping Method from Front-end in Magento 2?
In most cases, it happens when you do not want to offer a free shipping method to your customers. But the orders are placed with a free shipping method by default from the admin grid.
In that case, as a site owner, you will want to remove or disable a free shipping method from the front end of your Magento 2 store. Well, to resolve this problem, we have come up with the ultimate solution to remove/disable custom free shipping in Magento2 from the front-end.
Let’s get started on how to remove/disable the custom free shipping method from the front-end in Magento 2.
Steps to remove/disable custom free shipping method from the front-end in Magento 2:
-
Step 1: Add Plugin Configuration
Go to the path
app\code\MageSpark\RemoveShipping\etc\di.xml,
and add the below 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="MageSpark\CustomShipping\Model\Carrier\CustomShipping"> <plugin name="disable_customshipping" type="MageSpark\RemoveShipping\Plugin\DisableCustomShipping" sortOrder="1"/> </type> </config>
-
Step 2: Create Plugin file
Go to the path
app\code\MageSpark\RemoveShipping\Plugin\DisableCustomShipping.php
and use the code below:
<?php namespace MageSpark\RemoveShipping\Plugin; use Magento\Backend\Model\Auth\Session; use MageSpark\CustomShipping\Model\Carrier\CustomShipping; class DisableCustomShipping { /** * @var Session */ private $_session; public function __construct( Session $session ) { $this->_session = $session; } /** * @param CustomShipping $subject * @param \Closure $proceed * @param $request * @return false|mixed */ public function aroundCollectRates( CustomShipping $subject, \Closure $proceed, $request ) { if (!$this->_session->isLoggedIn()) { return false; // Only allow this to be used from the admin system } return $proceed($request); } }
Thus, following the above steps, you can easily Remove/Disable Custom Free Shipping Method from Front-end in Magento 2. If you have any questions or face any kind of problem, please contact us.