Md. Mehedi Hassan
Md. Mehedi Hassan

Reputation: 93

How to find the states/cities of any country in WooCommerce

I know that according to the method below I can get the country in woocommerce:

global $woocommerce;
$woocommerce->customer->get_shipping_country()

or

WC()->customer->get_shipping_country()

But I want to know that how to find the states/cities of any country.

Upvotes: 2

Views: 1603

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254378

In WooCommerce, you can only get states (or regions) from a country using:

$country_code = WC()->customer->get_shipping_country();

$states_array = WC()->countries->get_states( $country_code ); // States array for a country

You can get the customer shipping state with: WC()->customer->get_shipping_state();.
You can get the customer shipping city with: WC()->customer->get_shipping_city();.

Upvotes: 2

Related Questions