Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Sort WooCommerce shipping rates from lowest to highest cost.
- Add the below code to your functions.php file. */
- add_filter( 'woocommerce_package_rates' , 'rd_sort_shipping_methods', 10, 2 );
- function rd_sort_shipping_methods( $rates, $package ) {
- //Check to see if there are any rates
- if ( empty( $rates ) ) return;
- //Get a list of rates
- $temp = array();
- foreach( $rates as $rate ) {
- $temp[] = $rate->cost;
- }
- //Sort the rates based on cost
- array_multisort( $temp, $rates );
- return $rates;
- }
Add Comment
Please, Sign In to add comment