Skip to content

Instantly share code, notes, and snippets.

@nczz
Created June 14, 2019 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nczz/2a4d05b8e6abf64bcff7b96074597f8b to your computer and use it in GitHub Desktop.
Save nczz/2a4d05b8e6abf64bcff7b96074597f8b to your computer and use it in GitHub Desktop.
[WooCommerce] 運送方法項目的排序控制(由運費高低排序)
<?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