Список стран и стоимость доставки в woocommerce - PullRequest
0 голосов
/ 21 октября 2019

Я хочу вернуть массив стран с их ценой доставки в php.

У меня уже есть список стран с:

$countryClass = new WC_Countries();
$countryList = $countryClass->get_shipping_countries();

Но, похоже, найти доставку не представляется возможнымстоимость с:

$shipping = new WC_Shipping();
$shippingMethods = $shipping->get_shipping_methods(true);

Кто-нибудь имел эту проблему или нашел проблемы?

1 Ответ

0 голосов
/ 21 октября 2019

Нашли ответы, может ли это кому-нибудь как-то помочь

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;

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...