WC_REST_General_Settings_V4_Controller::validate_country_or_state_code
Validate country or state code.
Метод класса: WC_REST_General_Settings_V4_Controller{}
Хуков нет.
Возвращает
true|false. Valid or not valid.
Использование
// private - только в коде основоного (родительского) класса $result = $this->validate_country_or_state_code( $country_or_state );
- $country_or_state(строка) (обязательный)
- Country or state code.
Код WC_REST_General_Settings_V4_Controller::validate_country_or_state_code() WC REST General Settings V4 Controller::validate country or state code WC 10.3.4
private function validate_country_or_state_code( $country_or_state ) {
list( $country, $state ) = array_pad( explode( ':', (string) $country_or_state, 2 ), 2, '' );
if ( '' === $country ) {
return false;
}
$country_codes = array_keys( WC()->countries->get_countries() );
if ( ! in_array( $country, $country_codes, true ) ) {
return false;
}
if ( '' === $state ) {
return true;
}
$states_for_country = WC()->countries->get_states( $country );
if ( empty( $states_for_country ) ) {
return false;
}
return isset( $states_for_country[ $state ] );
}