Last active
March 23, 2021 17:45
-
-
Save rynaldos-zz/02d0236fbcffcc88c3f90ef851b58c05 to your computer and use it in GitHub Desktop.
[WooCommerce] Sort the shipping prices by cost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'woocommerce_package_rates' , 'sort_woocommerce_available_shipping_methods_by_cost', 10, 2 ); | |
| function sort_woocommerce_available_shipping_methods_by_cost( $rates, $package ) { | |
| if ( ! $rates ) { | |
| return; | |
| } | |
| $tmp = array(); | |
| foreach( $rates as $rate ) { | |
| $tmp[] = $rate->cost; | |
| } | |
| array_multisort( $tmp, SORT_ASC, $rates ); | |
| return $rates; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment