2

Store -> Settings -> Configuration -> Sales -> Shipping Methods -> Free Shipping

How can I disable this default feature of Magento in frontend only?

0

You can write a plugin for the free shipping method:

etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- PLUGINS: -->
    <type name="Magento\OfflineShipping\Model\Carrier\Freeshipping">
        <plugin name="mageworx_disable_free_shipping" type="MageWorx\DisableFreeShipping\Plugin\DisableFreeShippingOnFront"/>
    </type>
</config>

MageWorx\DisableFreeShipping\Plugin\DisableFreeShippingOnFront

<?php

namespace MageWorx\DisableFreeShipping\Plugin;

use Magento\Framework\App\State;

/**
 * Class DisableFreeShippingOnFront
 */
class DisableFreeShippingOnFront
{
    /**
     * @var State
     */
    private $state;

    /**
     * @param State $state
     */
    public function __construct(
        State $state
    ) {
        $this->state = $state;
    }

    /**
     * @param \Magento\OfflineShipping\Model\Carrier\Freeshipping $subject
     * @param callable $proceed
     * @param \Magento\Quote\Model\Quote\Address\RateRequest $request
     * @return \Magento\Shipping\Model\Rate\Result|bool
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function aroundCollectRates(
        \Magento\OfflineShipping\Model\Carrier\Freeshipping $subject,
        callable $proceed,
        \Magento\Quote\Model\Quote\Address\RateRequest $request
    ) {
        if ($this->state->getAreaCode() === \Magento\Framework\App\Area::AREA_FRONTEND) {
            return false;
        }

        return $proceed($request);
    }
}

Don't forget to rename the MageWorx\DisableFreeShipping to yours vendor and module names.

  • Coming from m1 and is totally new at m2, what folder/path do I need to achieve this? – thedeadlyone Oct 15 '18 at 13:08
  • vendor/module/etc/di.xml and vendor/module/Plugin/DisableFreeShippingOnFront.php where the vendor/module should be replaced with your vendor-name and module-name. – Siarhey Uchukhlebau Oct 15 '18 at 14:36

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.