You may have setup different shipping rates in your WooCommerce store. What you want and need to charge for shipping is different in each webshop and it is very hard to set things up exactly the way you need it. In this post I will show you how you can only show the cheapest shipping method or the most expensive one.

Only show the cheapest shipping rate

One of the reasons you might want to only show the cheapest rate is because you’re using the different shipping rates form different shipping carriers. To make it easier to your customers you may only want to to show the cheapest shipping rate. To filter out the other rates you can use the following custom code;

This code will ensure only the cheapest shipping rate of ALL your rates is being shown. Keep in mind that this could also be free shipping if that is something you’re offering.

Only show the most expensive shipping rate

There are also different reasons why you may want to only show the most expensive shipping rate available. For example, if you’ve setup shipping rates with a cost based on the class. It could be that you can include some of the lighter items you sell within a heavier/bigger package. In that case it would be good to only show the most expensive shipping rate so you will not lose money on the shipping cost.

The following code is almost the same as the code above and can be used in the same way.

Only show free shipping when available

If you offer free shipping rates you may also want to hide the other shipping rates as it doesn’t always make sense to offer paid shipping when there’s also free shipping available (sometimes it is, but it could be that the free shipping/paid shipping are exactly the same).

The following code will only show all the free shipping rates, meaning that if you’ve setup local pickup for example this will still be a option for the user. With the following code only the free shipping rates will show when there is a free shipping available, but it does make sure that it shows the regular shipping rates when local pickup is available (you probably do want to offer the choice to pickup or ship).

Closing words

Showing only one correct shipping rate will help your customers with the checkout as they’ve got one less decision to make. These code snippets will hopefully help you show the right shipping rates in your webshop.

Please leave a comment below if this was helpful for you, or if you ran into any challenges 🙂

Jeroen Sormani

I'm a professional WordPress plugin developer on a mission to create the best plugins for my clients. I'm specialised in developing general WordPress, WooCommerce and Easy Digital Downloads plugins.

Interested in talking about a WordPress project? Get in touch!

Follow me on Twitter

34 thoughts on “Only show free/cheapest/most expensive shipping in WooCommerce

Thomas K December 7, 2015 at 3:40 pm

Wicth file does this go into?
Tried with functions.php in my child theme and the site broke

jeroen December 7, 2015 at 6:16 pm

Hi Thomas,

The code goes in your functions.php file.
Here’s a blog I wrote some time ago about adding code snippets to your site for more details: https://aceplugins.com/how-to-add-a-code-snippet/

Jeroen

Deniz February 22, 2016 at 10:11 pm

Wow Jeroen! You really saved my time. 🙂 hah! Thank you so much.

Vic May 18, 2016 at 4:25 pm

Hi Jeroen,

Would it also be possible to only select the most expensive shipping method instead of hiding the others?

jeroen May 19, 2016 at 8:04 pm

Hi Vic,

It is possible, but you’d need a different code snippet then this one 😉 This code snippet is in the wrong place for doing that action.

One challenge you’d already have if you do this, is that in WC 2.6 there will be some big changes regarding shipping, and giving priority to certain shipping rates would also get a overhaul. (just something good to know before spending hours on this and having to do it again in a few months 😉

Cheers,
Jeroen

Bob the webbuilder May 30, 2016 at 10:11 am

Hi Jeroen,

Thanks for sharing, works fine!

Mickey July 14, 2016 at 4:29 pm

Hey Jeroen,

Is there a way to show the most expensive method plus a free pick-up method?

Looking forward to your reply.

Bij voorbaat dank 🙂

Mickey

Matt October 14, 2016 at 1:15 pm

Hi Jeroen,

Would really love to know if this one was possible too…. Thanks!

Matt

Tije October 1, 2016 at 9:10 pm

Hi jeroen,

I would like know the same as Mickey! Most expensive method + the option for free pick-up.

ooking forward to your reply.

Bij voorbaat dank ?

Mickey

Ashley December 6, 2016 at 10:40 am

This only ever shows one option, if there are two or more ‘most expensive’ options, how would I get them all to display?

Jeroen December 7, 2016 at 2:21 pm

Hi Ashley,

Do you mean when there are two rates with the same cost?
In that case you’d want to modify the code snippet to check for that and ensure its also saved when thats the case. It would be relatively easy to modify it to those needs.

Cheers,
Jeroen

Damjan Markovič August 2, 2017 at 1:18 pm

Great tutorials, Jeroen!

I have one question – are you aware of a way, to use the “per order” shipping calculation type, but make it choose the CHEAPEST instead of the most expensive shipping class in the cart?

So if I have shipping class A that costs 10€ (flat rate) and shipping class B that costs 20€ and I have one of each products in the cart, it would only charge 10€.

Thanks again and all the best!

Jeroen August 2, 2017 at 9:45 pm

Hi Damjan,

You could setup rates in WC core and then setup the cost per shipping class; and only set one per shipping rate.
Then use a code from this page to only show the cheapest rate available.

Alternatively you can give my Advanced Shipping plugin a try which would allow you to setup conditions in such manner that you don’t need such custom code 😉

Cheers,
Jeroen

Gaetan August 23, 2017 at 2:53 pm

Hi Jeroen, I use fixed rate and then have 2 shipping classes, one is free and the other 6,90. Woocommerce will show method title and the cost like in example: “PostNL €6,90” But with the shipping class with 0 cost it will only show “PostNL” instead of “PostNL €0,-” If i add a shipping method, i could make it work just bij the method title, would be something like “PostNL Pakketpost” and the other “PostNL Brievenbuspost Gratis” But then it shows both options and a radio button. Can you shine some light on the matter?

Tad December 12, 2017 at 10:03 pm

Awesome thank you dear Jeroen Sormani.

Tad December 12, 2017 at 10:21 pm

I have the same issue with tax rates. Is there any way to only show tax field when state is selected to CA or based on our Woocommerce tax nexus setting?

Thank you

Jeroen December 13, 2017 at 9:57 am

Hi Tad,

Taxes are something completely different, its likely possible, but you can’t use this code snippet as a basis for it, I’ll differ too much to be of any use for that.

Regards,
Jeroen

Tad December 15, 2017 at 1:31 am

Hello Jeroen,

Got it, Thank you for replying back,

I have a question regarding Sales Tax,

Would you be able to provide a peace of code to put into theme functions.php file, so if Tax is $0 then instead of $0 let it show Free, like Tax Free.

With Gratitude.

Tad December 15, 2017 at 1:50 am

or at least when customer have not yet insert zip code, tax field won’t show in the checkout page unless zip code is entered.

Thank you.

Jean Masman September 5, 2018 at 4:36 pm

I just tried this and it errors out. Do you have an updated code? Looking for the most expensive option to come up. Ideally would like all the shipping to just add up if that is possible.
Thank you!

Jeroen Sormani September 6, 2018 at 9:51 am

No known issues with the snippet – can you post the error you’re getting?

Most errors I see are coming from a wrong implementation: https://aceplugins.com/how-to-add-a-code-snippet/

Brandon May 30, 2019 at 11:55 pm

Thank you for the only show the cheapest shipping rate snippet Jeroen. Using with USPS and UPS and works as described.

Russ October 4, 2019 at 10:56 am

Hi,
Thanks for your code snippets – really helpful.

I’m actually trying to achieve the following and wondered if your code can help achieve this:

Display just the most expensive option, unless there is a free shipping option, in which case just show the free.

I’ve tried using the 2 code snippets together but the most expensive always beats the free.

Any help is much appreciated.

Jeroen Sormani October 4, 2019 at 11:07 am

Hi Russ,

You’d likely need to combine and customize the 2 snippets a bit to work nicely together.
If you’d need help with that, feel free to reach out through the contact form.

Cheers,
Jeroen

matt November 8, 2019 at 3:17 am

is this a way to do this for only WAS methods and it not be applied for standard woocomcerce shipping methods, that way I can still have it display only the most expensive shipping class but still also have the options to appear for express delivery

Jeroen Sormani November 8, 2019 at 9:28 am

Hi Matt,

With a change/customization in the script it is possible to only apply this to specific rates.

Cheers,
Jeroen

Anmarie November 15, 2019 at 3:41 am

Thank you for this code. It worked perfectly for me!

Excuse my ignorance, but what do the values 10 and 2 represent in this line:

add_action( ‘woocommerce_package_rates’, ‘my_only_show_cheapest_shipping_rate’, 10, 2 );

Just out of interest. Thanks again!

Alex October 20, 2020 at 8:45 am

Excellent, many thanks for the snippet

Julian January 3, 2021 at 1:05 pm

Hello Jeroen, how you doing? 😀

Thank you for your solutions, they work well for me but I would need something in between what you have done.

I was wondering how I could combine the following…. Show the most expensive shipping but if free shipping is available, show the free shipping first.

Thank you and happy new year!

Willy March 7, 2021 at 8:15 pm

Hello Jeroen,
Thank you for the helpful post. I’m wondering if there’s a way to hide shipping options that are too expensive, for example if it is over $100.
Thank you in advance! Really appreciate any help on this.
Best regards,
Willy

Jeroen Sormani March 8, 2021 at 10:32 am

Hi Willy,

Sure, the code can be modified to check for any rates over $100 and hide those accordingly. I’d recommend to use the lower snippet as a starting point as that seems to be the closest to what you’re looking for.

Cheers,
Jeroen

WOKEBY October 5, 2021 at 10:17 pm

Thanks a lot for the code!
It helped me to solve my issue.
I need to use different classes because I need to set different shipping companies.
Otherwise I loose the automatic label creation functionality.

Leave a Reply