WooCommerce

Sorting Shipping Rates Low To High On WooCommerce

For any websites that need/request shipping rates to display from lowest to highest, just add this snippet of code below.

After that, you should be good to go!

add_filter( 'woocommerce_package_rates' , 'businessbloomer_sort_shipping_methods', 10, 2 );
function businessbloomer_sort_shipping_methods( $rates, $package ) {
    if ( !$rates ) return;
    $tmp = Array();
    foreach( $rates as $ma ) {
        $tmp[] = $ma->cost;
    }
    array_multisort( $tmp, $rates );
    return $rates;
}
See our featured website design work

Check out some of the beautiful websites we’ve built for over 2,000 clients.

We offer WordPress support & maintenance

Shake the stress of ongoing maintenance with plans supported by our team of WordPress experts.

Related articles