WC_REST_Data_Countries_Controller::get_country() public WC 1.0
Get a list of countries and states.
{} Это метод класса: WC_REST_Data_Countries_Controller{}
Хуков нет.
Возвращает
Массив/Разное
. Response data, ready for insertion into collection data.
Использование
$WC_REST_Data_Countries_Controller = new WC_REST_Data_Countries_Controller(); $WC_REST_Data_Countries_Controller->get_country( $country_code, $request );
- $country_code(строка) (обязательный)
- Country code.
- $request(WP_REST_Request) (обязательный)
- Request data.
Код WC_REST_Data_Countries_Controller::get_country() WC REST Data Countries Controller::get country WC 5.2.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;
}