Show Only WooCommerce Free Shipping When Available

We’ve got an Ask Sell with WP question today about WooCommerce free shipping from Andrea:

Can I hide the other shipping options when there are free shipping choices? I tried the snippet in the WooCommerce doc page but I think it doesn’t work for me because I’m not using the “Free Shipping” one in my zone, but my shipping is still free because I use shipping classes.


This one is an interesting question, and we can definitely hide other rates when WooCommerce free shipping is available, regardless of what kind of shipping method it is.

The document Andrea’s referring to is this guide to hiding other methods if free shipping is available. However, the snippet in that document is indeed pretty specific.

That code looks for the free_shipping rate — or those that you add to a zone with the “Free Shipping” type (ie, the ones you can set a cart threshold for, or use coupons to enable). However, this does not look for other sorts of free rates, like a free flat rate.

The good news here is that we can use the same hook that snippet uses — the woocommerce_package_rates filter — to help us modify which rates are available to the customer.

WooCommerce Free Shipping: The Code

Let’s start with the code here, and then show you what it will do. If you’re not sure how to add custom code to your site, be sure to read this guide, as this change requires a snippet.

So the filter I mentioned gives us access to an array of rates in the cart. We can access these rates, check the cost of each rate, then only spit back out the free ones. If there are no free ones, then we can show the original rates we started with.

Here’s a look at that snippet:

Now notice the part I have commented out — that may or may not apply to you, so let’s take a look at what this code will do, and then you can determine whether you need it or not.

WooCommerce Free Shipping: “Free Shipping” Rate

If you have the “Free shipping” method in use in your store, you could have used the documentation that WooCommerce has provided. However, our snippet will still work just fine with that since we’re checking the cost of the rate, not the kind of method it is.

If you had free shipping available for your product, it would be shown along with all possible rates in the cart (though it’s at least selected by default):

WooCommerce Free Shipping Display
Default Free Shipping Display

However, with our snippet added, this will now only show the “Free Shipping” rate when it’s available:

Updated WooCommerce Free Shipping Display
Updated Free Shipping Display

If free shipping were not available, the other rates would be shown normally.

WooCommerce Free Shipping: Free Flat Rates

Now what if you have a free rate, but it’s a different kind of rate, like a flat rate? I’ve seen merchants do this with shipping classes specifically, as outlined in this post.

Our snippet will work for this set up, too. By default, all available rates for the zone are shown:

Woocommerce free shipping class
Free shipping class

With our snippet, even though this is a “Flat Rate” method, because it costs $0, we recognize it as a free method, and hide the others.

Updated WooCommerce free shipping class
Free shipping class + snippet

WooCommerce Free Shipping: Multiple Free Rates

Now for the final set up with our snippet. If you have multiple ways of achieving free shipping, like both flat rates and free shipping methods, these could conceivably be shown together in the cart shipping options by default.

WooCommerce Multiple free rates
Multiple free rates

Our snippet will currently recognize that both of these rates are free, and will show both of them to the customer. This might be handy if you have more descriptive “free rate” labels than I do and there are differences between them smile

WooCommerce Multiple free rates + snippet
Multiple free rates + snippet

If you only want to show one of your WooCommerce free shipping rates at any given time, you can uncomment out the final break; in my snippet — delete the two leading slashes. This will tell the code to stop after it finds the first free shipping method and use that for the customer.


That’s a wrap! Hope this helps you with your WooCommerce free shipping set up Andrea bigsmile


Cover photo credit: Stefan Baudy (CC BY 2.0 license)

Beka Rice
Beka is the head of product at Jilt. She works on app improvements, integration plugins, helping merchants improve recovery campaigns, and shares tutorials on reducing abandonment or improving recovery on our blog.

2 Comments

  1. Very useful and it works great but… how to create exceptions for some shipping methods?
    For example, if you have, among your shipping methods, the “pick up in store” option (that is “de facto” a free shipping method), and you want this option always visible.

Leave a Reply

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