Guest User

Untitled

a guest
Jun 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /* Sort WooCommerce shipping rates from lowest to highest cost.
  2. Add the below code to your functions.php file. */
  3.  
  4. add_filter( 'woocommerce_package_rates' , 'rd_sort_shipping_methods', 10, 2 );
  5.  
  6. function rd_sort_shipping_methods( $rates, $package ) {
  7.  
  8. //Check to see if there are any rates
  9. if ( empty( $rates ) ) return;
  10.  
  11. //Get a list of rates
  12. $temp = array();
  13. foreach( $rates as $rate ) {
  14. $temp[] = $rate->cost;
  15. }
  16.  
  17. //Sort the rates based on cost
  18. array_multisort( $temp, $rates );
  19.  
  20. return $rates;
  21.  
  22. }
Add Comment
Please, Sign In to add comment