WooCommerce allows anyone to sort their shipping rates through the Shipping Zones settings. Unfortunately its not always possible to all the shipping rates as some may not be available directly from within the shipping zones. For example, multiple shipping rates from live carrier quotes can be retrieved through an API, and usually are setup with only one shipping rate.
In this post I’ll show how you can easily sort the shipping rates by their cost from low to high and high to low with a small code snippet.
When deciding how you want to sort your shipping rates, keep in mind that WooCommerce uses the shipping option at the top as the default selected shipping rate.
Sorting Shipping Rates from Low to High
The following code snippet will automatically sort all the shipping rates from low to high.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
With this small variation on that script it will only sort the shipping rates from a specific shipping method (say UPS). This way you can keep your custom sorting of the available rates in the shipping zones section, but still sort the shipping carrier rates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This snippet sorts all the shipping rates from high to low cost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lastly same as the low to high option this will sort only the shipping rates of the UPS shipping method from high to low.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
About the author:Jeroen Sormani is actively building WordPress, WooCommerce and Easy Digital Downloads plugins. Slightly obsessed by writing high quality code. Follow Jeroen on Twitter