Automattic\WooCommerce\StoreApi\Utilities
ValidationUtils::format_state
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() ValidationUtils::format state WC 10.4.3
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;
}