Php 列出商业中的国家和运输成本
我想返回一组国家,并以php显示其发货价格 我已经有了以下国家/地区列表:Php 列出商业中的国家和运输成本,php,wordpress,api,woocommerce,Php,Wordpress,Api,Woocommerce,我想返回一组国家,并以php显示其发货价格 我已经有了以下国家/地区列表: $countryClass = new WC_Countries(); $countryList = $countryClass->get_shipping_countries(); 但似乎无法通过以下方式找到运输成本: $shipping = new WC_Shipping(); $shippingMethods = $shipping->get_shipping_methods(true); 有人遇到
$countryClass = new WC_Countries();
$countryList = $countryClass->get_shipping_countries();
但似乎无法通过以下方式找到运输成本:
$shipping = new WC_Shipping();
$shippingMethods = $shipping->get_shipping_methods(true);
有人遇到过这个问题或发现了问题吗?找到了答案,如果这对某人有帮助的话
function getShippingCountry(){
$countryClass = new WC_Countries();
$countryList = $countryClass->get_shipping_countries();
$shippingZones = new WC_Shipping_Zones();
$deliveryZones = $shippingZones->get_zones();
$array = [];
foreach ($deliveryZones as $zone){
if(isset($countryList[$zone['zone_locations'][0]->code])){
foreach ($zone['shipping_methods'] as $shippingMethod){
if(!isset($array[$zone['zone_name']]) || $array[$zone['zone_name']] < $shippingMethod->instance_settings['cost'] )
$array[$zone['zone_name']] = $shippingMethod->instance_settings['cost'];
}
}
}
return $array;
函数getShippingCountry(){
$countryClass=新的WC_国家();
$countryList=$countryClass->get_shipping_countries();
$shippingZones=新WC_Shipping_Zones();
$deliveryZones=$shippingZones->get_zones();
$array=[];
foreach($deliveryZones作为$zone){
if(isset($countryList[$zone['zone_locations']][0]->代码]){
foreach($zone['shipping_methods']作为$shippingMethod){
如果(!isset($array[$zone['zone_name']])| |$array[$zone['zone_name']]<$shippingMethod->instance_settings['cost'])
$array[$zone['zone\u name']=$shippingMethod->instance\u settings['cost'];
}
}
}
返回$array;
}