I created a Custom Free Shipping method and want to disable only in front end.

I try using getAreaCode() check here..but not working in Magento 2.4.0.

Please help if you know.


Please try this code. It will help you


<?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="Suraj\CustomShipping\Model\Carrier\Customshipping">
        <plugin name="disable_customshipping" type="Suraj\CustomShipping\Plugin\DisableEnableCustomShipping" sortOrder="1" />



    namespace Suraj\CustomShipping\Plugin;
    use Magento\Backend\Model\Auth\Session;
    class DisableEnableCustomShipping
         * @var Session
        private $_session;     
        public function __construct(
            Session $session
            $this->_session = $session;
        public function aroundCollectRates(
            \Suraj\CustomShipping\Model\Carrier\Customshipping $subject,
            \Closure $proceed,
        ) {
            if (!$this->_session->isLoggedIn()) {
                return false;   // Only allow this to be used from the admin system
            $result = $proceed($request);
            return $result;
  • Ok I am checking this code – Vikram Kumar Feb 15 at 10:45
  • Thanks! Its working for me. – Vikram Kumar Feb 15 at 10:52

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.