从woocommerce运送区域返回的区域位置

时间:2019-07-11 03:10:47

标签: wordpress woocommerce

我要在运输区域设置我希望商店送货的邮政编码列表。在woocommerce送货区域,我添加了72个邮政编码。我在functions.php中添加了一个函数来迭代区域,但是在执行代码时什么都没有发送。我一定做错了。请帮忙。

Here is the code in functions.php:

    function delivery_zone(){
        $delivery_zones = WC_Shipping_Zones::get_zones();
        foreach ((array) $delivery_zones as $key => $the_zone ) {
            $count = count($the_zone['zone_locations']);
            for($i=1;$i<=$count;$i++){
                $the_zone_code =  $the_zone['zone_locations'][$i]->code;
                return $the_zone_code;
            }
        } 
    } 



    add_shortcode( 'list_shipping_zones', 'delivery_zone' );


    #Then in my footer.php

    $postal_code = do_shortcode("[list_shipping_zones]");

But the results is only the very first postcode

0 个答案:

没有答案