How to Disable a Custom Free Shipping Method in Magento 2 (Frontend)

How to Remove/Disable Custom Free Shipping Method from Front-end in Magento 2?

In Magento 2, a shipping method shows on the frontend only if its carrier returns rates from collectRates(). To hide a custom “Free Shipping” method from checkout, intercept collectRates() with a plugin and return false for storefront requests.

This is useful when a custom shipping method exists for internal/admin use (testing, manual orders, special handling), but customers should never see or select it at checkout.

When this solution is the right fit

  • You want to remove a custom free shipping method from the frontend checkout.
  • You want the carrier to remain usable in the Admin (optional).
  • Your shipping method is implemented as a custom carrier that collects rates via collectRates().

How to remove or disable a custom free shipping method from the frontend in Magento 2

Step 1: Add the plugin configuration (di.xml)

Create or update this file:

app/code/MageSpark/RemoveShipping/etc/di.xml

Add a plugin for your carrier model class (replace the type name with your real carrier class):

<?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="magespark_disable_customshipping_frontend"
                type="MageSpark\RemoveShipping\Plugin\DisableCustomShipping"
                sortOrder="1"/>
    </type>

</config>

Tip: If your carrier class is different, update it here. The plugin must target the class that implements collectRates().

Step 2: Create the plugin file

Create this file:

app/code/MageSpark/RemoveShipping/Plugin/DisableCustomShipping.php

Paste the code below:

<?php

declare(strict_types=1);

namespace MageSpark\RemoveShipping\Plugin;

use MageSpark\CustomShipping\Model\Carrier\CustomShipping;
use Magento\Framework\App\Area;
use Magento\Framework\App\State;

class DisableCustomShipping
{
    private State $appState;

    public function __construct(State $appState)
    {
        $this->appState = $appState;
    }

    /**
     * Hide the carrier on the storefront by stopping rate collection.
     *
     * Returning false means "no rates", so Magento will not display this method.
     */
    public function aroundCollectRates(
        CustomShipping $subject,
        \Closure $proceed,
        $request
    ) {
        try {
            // Only block on the storefront (checkout/cart estimate).
            if ($this->appState->getAreaCode() === Area::AREA_FRONTEND) {
                return false;
            }
        } catch (\Exception $e) {
            // If area code isn't available, don't block rates (fail-safe).
        }

        return $proceed($request);
    }
}

Why this works

Magento 2 renders shipping methods only when the carrier returns valid rates. If collectRates() returns false, Magento treats it as “no available rates” for that carrier, so the method disappears from the frontend shipping list.

Deploy changes and test

Run these commands after adding the plugin:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush

Now verify:

  • Go to the cart and proceed to checkout.
  • Confirm the custom free shipping method is not visible in the shipping step.
  • If you use shipping estimation on the cart page, confirm it is hidden there too.
  • (Optional) In Admin → Sales → Orders → Create New Order, confirm it still appears if you want it for admin-only orders.

Common mistakes

  • Plugin targets the wrong class: You must plug into the carrier model class that actually collects rates.
  • Cache/compile not run: DI changes won’t apply until you compile and flush cache (especially in production mode).
  • Expecting this to apply conditionally: This approach hides the method for all storefront customers. If you need conditional logic (subtotal, country, customer group), you should implement those checks before returning false.

If you want to hide the shipping method only for specific countries, customer groups, cart totals, or store views, contact us and we’ll help you implement clean conditional logic without breaking checkout rate collection.

Talk to a Hyvä expert
Loading...