WordPress at Your Fingertips
function is not described

WC_REST_Setting_Options_V2_Controller::get_countries_and_states() private WC 3.0.7

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

{} It's a method of the class: WC_REST_Setting_Options_V2_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.

Code of WC_REST_Setting_Options_V2_Controller::get_countries_and_states() WC 5.9.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;
}