WooCommerce Code Reference

WC_Countries
in package

The WooCommerce countries class stores country/state data.

Table of Contents

$address_formats  : array<string|int, mixed>
List of address formats for locales.
$locale  : array<string|int, mixed>
Locales list.
$geo_cache  : array<string|int, mixed>
Cache of geographical regions.
__get()  : mixed
Auto-load in-accessible properties on demand.
countries_using_vat()  : array<string|int, string>
Gets an array of Non-EU countries that use VAT as the Local name for their taxes based on this list - https://en.wikipedia.org/wiki/Value-added_tax#Non-European_Union_countries
country_dropdown_options()  : mixed
Outputs the list of countries and states for use in dropdown boxes.
country_exists()  : bool
Check if a given code represents a valid ISO 3166-1 alpha-2 code for a country known to us.
estimated_for_prefix()  : string
Prefix certain countries with 'the'.
ex_tax_or_vat()  : string
Include the Ex Tax label.
get_address_fields()  : array<string|int, mixed>
Apply locale and get address fields.
get_address_formats()  : array<string|int, mixed>
Get country address formats.
get_allowed_countries()  : array<string|int, mixed>
Get countries that the store sells to.
get_allowed_country_states()  : array<string|int, mixed>
Get allowed country states.
get_base_address()  : string
Get the base address (first line) for the store.
get_base_address_2()  : string
Get the base address (second line) for the store.
get_base_city()  : string
Get the base city for the store.
get_base_country()  : string
Get the base country for the store.
get_base_postcode()  : string
Get the base postcode for the store.
get_base_state()  : string
Get the base state for the store.
get_continent_code_for_country()  : string
Get continent code for a country code.
get_continents()  : array<string|int, mixed>
Get all continents.
get_countries()  : array<string|int, mixed>
Get all countries.
get_country_calling_code()  : string|array<string|int, mixed>
Get calling code for a country code.
get_country_locale()  : array<string|int, mixed>
Get country locale settings.
get_country_locale_field_selectors()  : array<string|int, mixed>
Get JS selectors for fields which are shown/hidden depending on the locale.
get_default_address_fields()  : array<string|int, mixed>
Returns the fields we show by default. This can be filtered later on.
get_european_union_countries()  : array<string|int, string>
Gets an array of countries in the EU.
get_formatted_address()  : string
Get country address format.
get_shipping_continents()  : array<string|int, mixed>
Get continents that the store ships to.
get_shipping_countries()  : array<string|int, mixed>
Get countries that the store ships to.
get_shipping_country_states()  : array<string|int, mixed>
Get shipping country states.
get_states()  : false|array<string|int, mixed>
Get the states for a country.
get_vat_countries()  : array<string|int, string>
Gets an array of countries using VAT.
inc_tax_or_vat()  : string
Include the Inc Tax label.
load_country_states()  : mixed
Load the states.
shipping_to_prefix()  : string
Gets the correct string for shipping - either 'to the' or 'to'.
tax_or_vat()  : string
Correctly name tax in some countries VAT on the frontend.
trim_formatted_address_line()  : string
Trim white space and commas off a line.

Properties

$geo_cache

Cache of geographical regions.

private array<string|int, mixed> $geo_cache = array()

Only to be used by the get_* and load_* methods, as other methods may expect the regions to be loaded on demand.

Methods

__get()

Auto-load in-accessible properties on demand.

public __get(mixed $key) : mixed
Parameters
$key : mixed

Key.

Return values
mixed

countries_using_vat()

Gets an array of Non-EU countries that use VAT as the Local name for their taxes based on this list - https://en.wikipedia.org/wiki/Value-added_tax#Non-European_Union_countries

public countries_using_vat() : array<string|int, string>
Tags
deprecated
4.0.0
since
3.9.0
Return values
array<string|int, string>

country_dropdown_options()

Outputs the list of countries and states for use in dropdown boxes.

public country_dropdown_options([string $selected_country = '' ][, string $selected_state = '' ][, bool $escape = false ]) : mixed
Parameters
$selected_country : string = ''

Selected country.

$selected_state : string = ''

Selected state.

$escape : bool = false

If we should escape HTML.

Return values
mixed

country_exists()

Check if a given code represents a valid ISO 3166-1 alpha-2 code for a country known to us.

public country_exists(string $country_code) : bool
Parameters
$country_code : string

The country code to check as a ISO 3166-1 alpha-2 code.

Tags
since
5.1.0
Return values
boolTrue if the country is known to us, false otherwise.

estimated_for_prefix()

Prefix certain countries with 'the'.

public estimated_for_prefix([string $country_code = '' ]) : string
Parameters
$country_code : string = ''

Country code.

Return values
string

get_address_fields()

Apply locale and get address fields.

public get_address_fields([mixed $country = '' ][, string $type = 'billing_' ]) : array<string|int, mixed>
Parameters
$country : mixed = ''

Country.

$type : string = 'billing_'

Address type, defaults to 'billing_'.

Return values
array<string|int, mixed>

get_address_formats()

Get country address formats.

public get_address_formats() : array<string|int, mixed>

These define how addresses are formatted for display in various countries.

Return values
array<string|int, mixed>

get_allowed_countries()

Get countries that the store sells to.

public get_allowed_countries() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_allowed_country_states()

Get allowed country states.

public get_allowed_country_states() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_base_address()

Get the base address (first line) for the store.

public get_base_address() : string
Tags
since
3.1.1
Return values
string

get_base_address_2()

Get the base address (second line) for the store.

public get_base_address_2() : string
Tags
since
3.1.1
Return values
string

get_base_city()

Get the base city for the store.

public get_base_city() : string
Tags
version
3.1.1
Return values
string

get_base_postcode()

Get the base postcode for the store.

public get_base_postcode() : string
Tags
since
3.1.1
Return values
string

get_continent_code_for_country()

Get continent code for a country code.

public get_continent_code_for_country(string $cc) : string
Parameters
$cc : string

Country code.

Tags
since
2.6.0
Return values
string

get_continents()

Get all continents.

public get_continents() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_countries()

Get all countries.

public get_countries() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_country_calling_code()

Get calling code for a country code.

public get_country_calling_code(string $cc) : string|array<string|int, mixed>
Parameters
$cc : string

Country code.

Tags
since
3.6.0
Return values
string|array<string|int, mixed>Some countries have multiple. The code will be stripped of - and spaces and always be prefixed with +.

get_country_locale()

Get country locale settings.

public get_country_locale() : array<string|int, mixed>

These locales override the default country selections after a country is chosen.

Return values
array<string|int, mixed>

get_country_locale_field_selectors()

Get JS selectors for fields which are shown/hidden depending on the locale.

public get_country_locale_field_selectors() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_default_address_fields()

Returns the fields we show by default. This can be filtered later on.

public get_default_address_fields() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_european_union_countries()

Gets an array of countries in the EU.

public get_european_union_countries([string $type = '' ]) : array<string|int, string>
Parameters
$type : string = ''

Type of countries to retrieve. Blank for EU member countries. eu_vat for EU VAT countries.

Return values
array<string|int, string>

get_formatted_address()

Get country address format.

public get_formatted_address([array<string|int, mixed> $args = array() ][, string $separator = '<br/>' ]) : string
Parameters
$args : array<string|int, mixed> = array()

Arguments.

$separator : string = '<br/>'

How to separate address lines. @since 3.5.0.

Return values
string

get_shipping_continents()

Get continents that the store ships to.

public get_shipping_continents() : array<string|int, mixed>
Tags
since
3.6.0
Return values
array<string|int, mixed>

get_shipping_countries()

Get countries that the store ships to.

public get_shipping_countries() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_shipping_country_states()

Get shipping country states.

public get_shipping_country_states() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_states()

Get the states for a country.

public get_states([string $cc = null ]) : false|array<string|int, mixed>
Parameters
$cc : string = null

Country code.

Return values
false|array<string|int, mixed>of states

get_vat_countries()

Gets an array of countries using VAT.

public get_vat_countries() : array<string|int, string>
Tags
since
4.0.0
Return values
array<string|int, string>of country codes.

load_country_states()

Load the states.

public load_country_states() : mixed
Tags
deprecated
3.6.0

This method was used to load state files, but is no longer needed. @see get_states().

Return values
mixed

shipping_to_prefix()

Gets the correct string for shipping - either 'to the' or 'to'.

public shipping_to_prefix([string $country_code = '' ]) : string
Parameters
$country_code : string = ''

Country code.

Return values
string

tax_or_vat()

Correctly name tax in some countries VAT on the frontend.

public tax_or_vat() : string
Return values
string

trim_formatted_address_line()

Trim white space and commas off a line.

private trim_formatted_address_line(string $line) : string
Parameters
$line : string

Line.

Return values
string