问题描述
我知道按照下面的方法我可以在woocommerce中获取国家:
global $woocommerce;
$woocommerce->customer->get_shipping_country()
或
WC()->customer->get_shipping_country()
但我想知道如何找到任何国家/地区的州/市。
解决方法
在 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();
。