WooCommerce does not sort the shipping methods, services by default while displaying the shipping services on cart and checkout pages.
We do have a code snippet that will change the order of the shipping services based on value. From lowest rate to highest.
I suggest setting up the snippet in the code snippets plugin, this is a better process than adding it into your themes functions.php file which will be overwritten when you update the theme.
You can install the 'Code Snippets' plugin whilst logged into the WordPress backend or you can download the plugin here:
https://wordpress.org/plugins/code-snippets/
The code snippet to add in is:
add_filter( 'woocommerce_package_rates' , 'ew_sort_shipping_services_by_cost', 10, 2 );
function ew_sort_shipping_services_by_cost( $rates, $package ) {
if ( ! $rates ) return;
$rate_cost = array();
foreach( $rates as $rate ) {
$rate_cost[] = $rate->cost;
}
// using rate_cost, sort rates.
array_multisort( $rate_cost, $rates );
return $rates;
}
I have also added a screen shot of this code snippet set up in the code snippets plugin.
Comments
0 comments
Please sign in to leave a comment.