Created
October 4, 2018 10:41
-
-
Save varun-pluginhive/683bb169341200d59c4d3058d5ca06eb to your computer and use it in GitHub Desktop.
Snippet to sort the WooCommerce Shipping Rates in ascending order. PluginHive Plugins : https://www.pluginhive.com/plugins/
This file contains 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
/** | |
* Snippet to sort the WooCommerce Shipping Rates in ascending order. | |
* Created at : 04 Oct 2018 | |
* Updated at : 04 Oct 2018 | |
* PluginHive Plugins : https://www.pluginhive.com/plugins/ | |
* Gist Link : https://gist.github.com/varun-pluginhive/683bb169341200d59c4d3058d5ca06eb | |
*/ | |
add_filter( 'woocommerce_package_rates', function( $rates ){ | |
if( empty($rates) ) return $rates; | |
foreach( $rates as $rate ) { | |
$rate_cost[] = $rate->get_cost(); | |
} | |
array_multisort( $rate_cost, $rates ); | |
return $rates; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment