Hiding Other Shipping Methods When WooCommerce Free Shipping Is Active

Shipping management is one of the issues that WooCommerce users experience the most. Especially when the free shipping option is active, other shipping methods cannot be hidden, which does not suit the world’s most used e-commerce infrastructure such as WooCommerce. Today I will talk about how to hide other shipping methods while free shipping is […]

Hiding Other Shipping Methods When WooCommerce Free Shipping Is Active

Shipping management is one of the issues that WooCommerce users experience the most. Especially when the free shipping option is active, other shipping methods cannot be hidden, which does not suit the world’s most used e-commerce infrastructure such as WooCommerce. Today I will talk about how to hide other shipping methods while free shipping is active on your WooCommerce e-commerce sites.

After logging in to our WordPress admin panel, we created a free shipping script from WooCommerce> Settings> Shipping. In this scenario, free shipping must be active for orders of $150 and above.

As you can see in the image below, when the free shipping option we created on our WooCommerce site is active, the other shipping method is not hidden.

In fact, when the customer added $150 or more products to his/her cart, other shipping methods should be hidden and only “free shipping” option should be left.

So why is this important?

Although your customer is entitled to free shipping for orders of $150 and above, he / she pays extra shipping and this situation may be overlooked by the customers. When your customers notice this, they may ask you for the shipping fee or make bad comments on behalf of your brand on the internet and on social media sites. In order to avoid such a situation, you should hide other shipping methods while free shipping is active on your WooCommerce sites.

How to Hide Other Shipping Methods When Free Shipping Is Active?

You can prevent this problem with a simple code you add to your site. All you have to do is log in to your WordPress admin panel, then click the View> Theme Editor> functions.php file and add the code I gave you below to an available field.

function hide_shipping_when_free_is_available( $rates, $package ) {
	$new_rates = array();
	foreach ( $rates as $rate_id => $rate ) {
		// Only modify rates if free_shipping is present.
		if ( 'free_shipping' === $rate->method_id ) {
			$new_rates[ $rate_id ] = $rate;
			break;
		}
	}
	if ( ! empty( $new_rates ) ) {
		//Save local pickup if it's present.
		foreach ( $rates as $rate_id => $rate ) {
			if ('local_pickup' === $rate->method_id ) {
				$new_rates[ $rate_id ] = $rate;
				break;
			}
		}
		return $new_rates;
	}
	return $rates;
}
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );

If the View> Theme Editor option is not visible to you, connect to the hosting area of your site via CPANEL or FTP program and open public_html> wp-content> themes> YOUR THEME> functions.php file with a text editor and add the code and restore it.

If you added the code I shared above correctly, your customers can now place their orders with the free shipping option and other shipping methods will be hidden. I hope these codes I shared will be useful for you. You can send me any questions you have about the application from the comment field.

Leave a Reply

Your email address will not be published. Required fields are marked *