Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\General

Controller::validate_country_or_state_code │ private │ WC 1.0

Validate country or state code.

Метод класса: Controller{}

Хуков нет.

Возвращает

boolean. Valid or not valid.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->validate_country_or_state_code( $country_or_state );
$country_or_state(строка) (обязательный)
Country or state code.

Код Controller::validate_country_or_state_code() WC 11.2.2

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 ] );
}