WC_REST_Setting_Options_Controller::get_countries_and_states()
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() WC REST Setting Options Controller::get countries and states code WC 9.7.1
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; }