2

I have a magento 2.2.3 site. In checkout we have enabled two shipping options. Table rates and free shipping. Orders above 100$ we provide free shipping charges. But sometimes this does not work Suppose, the subtotal for particular order is 160$. After discounts or promotions etc order total comes as 60$. Then in the checkout free shipping options should not be displayed and table rates should be applied. Checkout shows both options. What I want is to display only one of the option based on the Order total not the subtotal. Could anyone please advice on this ??

1
  • how to apply condition on whole shipping collection Jun 27, 2019 at 12:08

1 Answer 1

0

You need to create a plugin of ShipmentEstimationInterface class.

di.xml

<type name="Magento\Quote\Api\ShipmentEstimationInterface">
    <plugin name="allow_company_shipping_methods" type="Vendor\Module\Plugin\ShippingPlugin"/>
</type>

ShippingPlugin.php

<?php
namespace Vendor\Module\Plugin;


class ShippingPlugin
{
   public function __construct(
       \Magento\Checkout\Model\Session $checkoutSession
    ) {
       $this->checkoutSession = $checkoutSession;
    }
   /**
     * Allow shipping methods
     *
     * @param \Magento\Quote\Api\ShipmentEstimationInterface $subject
     * @param \Magento\Quote\Api\Data\ShippingMethodInterface[] $methods
     * @return \Magento\Quote\Api\Data\ShippingMethodInterface[] $methods
     */
    public function afterEstimateByExtendedAddress(\Magento\Quote\Api\ShipmentEstimationInterface $subject, $methods) 
    {
        $grandTotal = $this->checkoutSession->getQuote()->getGrandTotal();
        foreach($methods as $key => &$method) {
            if($method->getMethodCode() == 'freeshipping' && $grandTotal < 60) {
                unset($methods[$key]);
            }
        } 
        return $methods;

    }


}

I hope it will work for you. Let me know in case any further assistance needed.

2
  • Hi Ramkishan thanks for the suggestion. I will try this out.
    – Kevin
    Jan 6, 2019 at 15:03
  • Any suggestions guys ?
    – Kevin
    Jan 6, 2019 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.