【问题标题】:How to find the states/cities of any country in WooCommerce如何在 WooCommerce 中查找任何国家/地区的州/城市
【发布时间】:2021-07-12 02:19:41
【问题描述】:
我知道按照下面的方法我可以在woocommerce中获取国家:
global $woocommerce;
$woocommerce->customer->get_shipping_country()
或
WC()->customer->get_shipping_country()
但我想知道如何找到任何国家/地区的州/城市。
【问题讨论】:
标签:
php
wordpress
woocommerce
location
country
【解决方案1】:
在 WooCommerce 中,您只能使用以下方式获取某个国家/地区的州(或地区):
$country_code = WC()->customer->get_shipping_country();
$states_array = WC()->countries->get_states( $country_code ); // States array for a country
您可以通过WC()->customer->get_shipping_state(); 获取客户发货状态。
您可以通过WC()->customer->get_shipping_city();获取客户发货城市。