WC_REST_General_Settings_V4_Controller::get_country_state_options
Get country/state options for single select country field.
Method of the class: WC_REST_General_Settings_V4_Controller{}
No Hooks.
Returns
Array. Country/state options.
Usage
// private - for code of main (parent) class only $result = $this->get_country_state_options();
WC_REST_General_Settings_V4_Controller::get_country_state_options() WC REST General Settings V4 Controller::get country state options code WC 10.3.6
private function get_country_state_options() {
$countries = WC()->countries->get_countries();
$states = WC()->countries->get_states();
$country_state_options = array();
foreach ( $countries as $country_code => $country_name ) {
$country_states = $states[ $country_code ] ?? array();
if ( empty( $country_states ) ) {
$country_state_options[ $country_code ] = $country_name;
} else {
foreach ( $country_states as $state_code => $state_name ) {
$country_state_options[ $country_code . ':' . $state_code ] = $country_name . ' — ' . $state_name;
}
}
}
return $country_state_options;
}