You are running a WooCommerce store and you should make sure your customer’s experience is quick and painless. Offering free shipping is a huge incentive for such cases. When customers find free shipping rates available in your store, they may be less willing to select other paid methods. When you hide these extra paid shipping options on the cart and checkout page, then customers will only see free delivery as an option – which is what customers always prefer! This will encourage them to buy from you because they’re not going through the trouble of finding an alternative store with higher prices!
By default, WooCommerce shows all the available shipping methods. So you need to write some kind of code or use a specific plugin to hide other shipping rates when free shipping is available in WooCommerce. In this tutorial, we are going to explore how to achieve this with just a little bit of code.
What are the default shipping methods?
Let’s consider an example. We have a WooCommerce store with all three default shipping methods enabled.
The default shipping methods are:
- Flat Rate
- Free Shipping, and
- Local Pickup
When a customer lands on our site and adds a product to his cart, he has been given all these default shipping options. Look at this screenshot.
You can see from the above screenshot, though free shipping is available, the customer can still see the other two paid shipping methods. It is definitely a wise decision to hide these paid options from the customer because the customer is sure to choose the free delivery. If you hide the paid options for this case, it is going to boost up the customer’s buying experience.
How to hide other shipping methods when free shipping is available.
To achieve this, open your theme’s functions.php file and copy/paste the below code. Save and re-upload the file to your server.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function cdxn_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'cdxn_hide_shipping_when_free_is_available', 100 );
Congratulations! You have made it. From now on, as soon as there is a free shipping rate available for a customer, all other paid shipping options will automatically be hidden from them. A screenshot after hiding the paid shipping options will look like below.
In the above code snippet, we have used WooCommerce woocommerce_package_rates
filer and hooked our function into this filter. The function is checking all the available shipping methods and looping through them. Once it finds a free_shipping
method id, it breaks out the loop and returns the free shipping rate as the only available shipping method. Hooking this functions into the woocommerce_package_rates
filter automatically hides all other paid shipping options.
Not getting any changes in the shipping methods after adding the above code snippet? You may need to clear the WooCommerce transients cache.
Visit Dashboard->WooCommerce->Status. You will see ‘WooCommerce transients’ at the top of the page. Click the ‘Clear transients’ button and refresh the cart/checkout page
So, don’t delay and hide shipping rates when free shipping is available at WooCommerce for your customer.
We hope you found this tutorial informative and helpful. If there are any questions, let us know using the comments section below. If you would like to explore more WooCommerce tutorials, do not wait and visit this link right now.
Thank you.