Câu trả lời được chấp nhận không còn hoạt động như của WooCommerce phiên bản 2.6. Nó vẫn cung cấp cho một đầu ra, nhưng đầu ra đó là sai, vì nó không sử dụng các vùng vận chuyển mới được giới thiệu.
Để có được số tiền chi tiêu tối thiểu cho miễn phí vận chuyển trong một khu vực cụ thể, hãy thử u chức năng này, tôi đặt lại với nhau:
/**
* Accepts a zone name and returns its threshold for free shipping.
*
* @param $zone_name The name of the zone to get the threshold of. Case-sensitive.
* @return int The threshold corresponding to the zone, if there is any. If there is no such zone, or no free shipping method, null will be returned.
*/
function get_free_shipping_minimum($zone_name = 'England') {
if (! isset($zone_name)) return null;
$result = null;
$zone = null;
$zones = WC_Shipping_Zones::get_zones();
foreach ($zones as $z) {
if ($z['zone_name'] == $zone_name) {
$zone = $z;
}
}
if ($zone) {
$shipping_methods_nl = $zone['shipping_methods'];
$free_shipping_method = null;
foreach ($shipping_methods_nl as $method) {
if ($method->id == 'free_shipping') {
$free_shipping_method = $method;
break;
}
}
if ($free_shipping_method) {
$result = $free_shipping_method->min_amount;
}
}
return $result;
}
Đặt chức năng trên trong functions.php và sử dụng nó trong một khuôn mẫu như như vậy:
$free_shipping_min = '45';
$free_shipping_en = get_free_shipping_minimum('England');
if ($free_shipping_en) {
$free_shipping_min = $free_shipping_en;
}
echo $free_shipping_min;
Hy vọng điều này sẽ giúp người khác.
Nguồn
2017-06-26 10:48:30
Cảm ơn bạn. Nó đã làm việc :) – Vidhi
Tôi đã bỏ phiếu cho câu trả lời của bạn, nhưng mã này không hoạt động nữa với WooCommerce Phiên bản 2.6+… Tôi có một câu trả lời chức năng cho phiên bản thực tế của WooCommerce tại đây: http://stackoverflow.com/a/42201311/ 3730754 – LoicTheAztec