Automattic\WooCommerce\StoreApi\Utilities

ValidationUtils::format_state()publicWC 1.0

Format a state based on the country. If country has defined states, will return a valid upper case state code.

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

Хуков нет.

Возвращает

Строку.

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

$ValidationUtils = new ValidationUtils();
$ValidationUtils->format_state( $state, $country );
$state(строка) (обязательный)
State name or code (sanitized).
$country(строка) (обязательный)
Country code.

Код ValidationUtils::format_state() WC 8.7.0

public function format_state( $state, $country ) {
	$states = $this->get_states_for_country( $country );

	if ( count( $states ) ) {
		$state        = \wc_strtoupper( $state );
		$state_values = array_map( '\wc_strtoupper', array_flip( array_map( '\wc_strtoupper', $states ) ) );

		if ( isset( $state_values[ $state ] ) ) {
			// Convert to state code if a state name was provided.
			return $state_values[ $state ];
		}
	}

	return $state;
}