cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2: How to remove shipping methods if Free Shipping is available

Magento 2: How to remove shipping methods if Free Shipping is available

Customers who qualify for free shipping will also have paid shipping option shown, which may be confusing.

 

Is there a way to hide other shipping methods when free shipping method is available?

3 REPLIES

Re: Magento 2: How to remove shipping methods if Free Shipping is available

http://www.magestore.com/magento-2-tutorial/how-to-set-up-free-shipping-rules-in-magento-2/

this might help


lgarridoj wrote:

Customers who qualify for free shipping will also have paid shipping option shown, which may be confusing.

 

Is there a way to hide other shipping methods when free shipping method is available?


 

Re: Magento 2: How to remove shipping methods if Free Shipping is available

Hi, 

 

Did you get  any answer on this?

Did you create a new module?

Re: Magento 2: How to remove shipping methods if Free Shipping is available

Hello @pisha,

 

Magento\Quote\Model\ShippingMethodManagement.php

 

 

 public function getList($cartId)
{
	............
	$free=false;
	$freeOutput=[];
	foreach ($shippingRates as $carrierRates) {
		foreach ($carrierRates as $rate) {
			if($rate->getCode()=='freeshipping')
			{
				$free=true;
				$freeOutput[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
			}else{
				$output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
			}
		}
	}
	if($free==false)
	{
	return $output;
	}else{
	return $freeOutput;
	}
}

If work then you need to create plugin after afttergetList/aroundGetList() and implement same logic.

 

If my idea work then mark as solution.