WooCommerce Sort Shipping Methods By Cost

add_filter( 'woocommerce_package_rates' , 'kpry_sort_woocommerce_available_shipping_methods', 10, 2 );
function kpry_sort_woocommerce_available_shipping_methods( $rates, $package ) {
	//  if there are no rates don't do anything
	if ( ! $rates ) {
		return;
	}

	// get an array of prices
	$prices = array();
	foreach( $rates as $rate ) {
		$prices[] = $rate->cost;
	}

	// use the prices to sort the rates
	array_multisort( $prices, $rates );

	// return the rates
	return $rates;
}