Sorting Shipping Rates Low To High On WooCommerce

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;
}
Menu
Google Rating
5.0
Get a Quote