0

By default in my site I have enabled free shipping method if subtotal is greater than 150$. Now I have to disable free shipping method if subtotal after discount is greater than 150$ and enable table rate method. I have tried just to disable free shipping anyhow but not working.

<?php
namespace vendor\FreeShippingRule\Plugin;
use Magento\Quote\Api\ShipmentEstimationInterface;

class Shipping
{
    public function beforeAppend($subject, $result)
    {
        if (!$result instanceof \Magento\Quote\Model\Quote\Address\RateResult\Method) {
            return [$result];
        }

        if ($this->isMethodRestricted($result)) {
            $result->setIsDisabled(true);
        }

        return [$result];
    }

    public function isMethodRestricted($shippingModel)
    {
        $code = $shippingModel->getCarrier();
        $restrictedMethod = ['freeshipping'];

        if ($restrictedMethod && in_array($code, $restrictedMethod)) {
            return false;
        }

        return false;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.