Skip to content

Instantly share code, notes, and snippets.

@varun-pluginhive
Created October 4, 2018 10:41
Show Gist options
  • Save varun-pluginhive/683bb169341200d59c4d3058d5ca06eb to your computer and use it in GitHub Desktop.
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/
/**
* 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