Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.