如何在 WooCommerce 中查找任何国家/地区的州/市

问题描述

我知道按照下面的方法我可以在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();

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...