WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Schemas

AbstractAddressSchema::format_state() protected WC 1.0

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

{} It's a method of the class: AbstractAddressSchema{}

No Hooks.

Return

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->format_state( $state, $country );
$state(string) (required)
State name or code (sanitized).
$country(string) (required)
Country code.

Code of AbstractAddressSchema::format_state() WC 5.7.1

protected function format_state( $state, $country ) {
	$states = $country ? array_filter( (array) wc()->countries->get_states( $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;
}