WC_REST_Data_Countries_Controller::get_country()
Get a list of countries and states.
Method of the class: WC_REST_Data_Countries_Controller{}
No Hooks.
Return
Array|Mixed
. Response data, ready for insertion into collection data.
Usage
$WC_REST_Data_Countries_Controller = new WC_REST_Data_Countries_Controller(); $WC_REST_Data_Countries_Controller->get_country( $country_code, $request );
- $country_code(string) (required)
- Country code.
- $request(WP_REST_Request) (required)
- Request data.
WC_REST_Data_Countries_Controller::get_country() WC REST Data Countries Controller::get country code WC 9.8.1
public function get_country( $country_code, $request ) { $countries = WC()->countries->get_countries(); $states = WC()->countries->get_states(); $data = array(); if ( ! array_key_exists( $country_code, $countries ) ) { return false; } $country = array( 'code' => $country_code, 'name' => $countries[ $country_code ], ); $local_states = array(); if ( isset( $states[ $country_code ] ) ) { foreach ( $states[ $country_code ] as $state_code => $state_name ) { $local_states[] = array( 'code' => $state_code, 'name' => $state_name, ); } } $country['states'] = $local_states; return $country; }