WooCommerce Code Reference

ValidationUtils
in package

ValidationUtils class.

Helper class which validates and update customer info.

Table of Contents

format_state()  : string
Format a state based on the country. If country has defined states, will return a valid upper case state code.
get_states_for_country()  : array<string|int, mixed>
Get list of states for a country.
validate_state()  : bool
Validate provided state against a countries list of defined states.

Methods

format_state()

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

public format_state(string $state, string $country) : string
Parameters
$state : string

State name or code (sanitized).

$country : string

Country code.

Return values
string

get_states_for_country()

Get list of states for a country.

public get_states_for_country(string $country) : array<string|int, mixed>
Parameters
$country : string

Country code.

Return values
array<string|int, mixed>Array of state names indexed by state keys.

validate_state()

Validate provided state against a countries list of defined states.

public validate_state(string $state, string $country) : bool

If there are no defined states for a country, any given state is valid.

Parameters
$state : string

State name or code (sanitized).

$country : string

Country code.

Return values
boolValid or not valid.