Magento 2.2.2 remove other shipping methods and enable only free shipping if consumer total more than 100

You can do that by overriding the

\Magento\Quote\Model\ShippingMethodManagement::getShippingMethods function.

private function getShippingMethods(Quote $quote, $address)
{
    $output = [];
    $shippingAddress = $quote->getShippingAddress();
    $shippingAddress->addData($this->extractAddressData($address));
    $shippingAddress->setCollectShippingRates(true);

    $this->totalsCollector->collectAddressTotals($quote, $shippingAddress);
    $shippingRates = $shippingAddress->getGroupedAllShippingRates();
    foreach ($shippingRates as $carrierRates) {
        foreach ($carrierRates as $rate) {
            $output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
        }
    }
    return $output;
}

This method is responsible for providing all the available shipping methods. So all you have to do is, check the grand total of the quote and enable the respective methods.

Below are the modified lines to display only free shipping when order amount goes above 100.

foreach ($shippingRates as $carrierRates) {
    foreach ($carrierRates as $rate) {
        if ($quote->getGrandTotal() <= 100) {
            $output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
        } else {
            if ($rate->getMethod() == "freeshipping") {
                $output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
                break;
            }
        }

    }
}

Since this method is a private function, you can't use plugins. You can go with preference to achieve that.


The answer of @Ravindrasinh is half the answer: it explains how you can show a shipping method from a given amount. Your question is also about the inverse of this: hide certain shipping methods from a given amount.

What you need to do is write plugins after the collectRates()-methods of the given shipping methods so you can manipulate the outcome according to your own quote.


Now check screen short for apply free shipping and other shipping method Flat rate , table rate option in No then all are disable only free shipping enable Yes

Store -> Configuration -> Sales -> Shipping Method -> Free Shipping

enter image description here

Free shipping cart image

enter image description here