WC_REST_Setting_Options_Controller::get_countries_and_states()privateWC 3.0.7

Returns a list of countries and states for use in the base location setting.

Method of the class: WC_REST_Setting_Options_Controller{}

No Hooks.

Return

Array. Array of states and countries.

Usage

// private - for code of main (parent) class only
$result = $this->get_countries_and_states();

Changelog

Since 3.0.7 Introduced.

WC_REST_Setting_Options_Controller::get_countries_and_states() code WC 8.7.0

private function get_countries_and_states() {
	$countries = WC()->countries->get_countries();
	if ( ! $countries ) {
		return array();
	}
	$output = array();
	foreach ( $countries as $key => $value ) {
		$states = WC()->countries->get_states( $key );

		if ( $states ) {
			foreach ( $states as $state_key => $state_value ) {
				$output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value;
			}
		} else {
			$output[ $key ] = $value;
		}
	}
	return $output;
}