Created
June 14, 2019 17:08
-
-
Save nczz/2a4d05b8e6abf64bcff7b96074597f8b to your computer and use it in GitHub Desktop.
[WooCommerce] 運送方法項目的排序控制(由運費高低排序)
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
<?php | |
function mxp_sort_shipping_services_by_cost($available_shipping_methods, $package) { | |
if (!$available_shipping_methods) { | |
return; | |
} | |
$rate_cost_set = array(); | |
// 抽出運費多寡 | |
foreach ($available_shipping_methods as $rate) { | |
$rate_cost_set[] = $rate->cost; | |
} | |
// 排序 | |
array_multisort($rate_cost_set, $available_shipping_methods); | |
return $available_shipping_methods; | |
} | |
add_filter('woocommerce_package_rates', 'mxp_sort_shipping_services_by_cost', 11, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment