WooCommerce Code Reference

WC_Countries
in package

The WooCommerce countries class stores country/state data.

Table of Contents

$address_formats  : array
List of address formats for locales.
$locale  : array
Locales list.
__get()  : mixed
Auto-load in-accessible properties on demand.
countries_using_vat()  : 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.
estimated_for_prefix()  : string
Prefix certain countries with 'the'.
ex_tax_or_vat()  : string
Include the Ex Tax label.
get_address_fields()  : array
Apply locale and get address fields.
get_address_formats()  : array
Get country address formats.
get_allowed_countries()  : array
Get countries that the store sells to.
get_allowed_country_states()  : array
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
Get all continents.
get_countries()  : array
Get all countries.
get_country_calling_code()  : string|array
Get calling code for a country code.
get_country_locale()  : array
Get country locale settings.
get_country_locale_field_selectors()  : array
Get JS selectors for fields which are shown/hidden depending on the locale.
get_default_address_fields()  : array
Returns the fields we show by default. This can be filtered later on.
get_european_union_countries()  : string[]
Gets an array of countries in the EU.
get_formatted_address()  : string
Get country address format.
get_shipping_continents()  : array
Get continents that the store ships to.
get_shipping_countries()  : array
Get countries that the store ships to.
get_shipping_country_states()  : array
Get shipping country states.
get_states()  : false|array
Get the states for a country.
get_vat_countries()  : 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

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() : string[]
Tags
deprecated
4.0.0
since
3.9.0
Return values
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

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
Parameters
$country : mixed = ''

Country.

$type : string = 'billing_'

Address type, defaults to 'billing_'.

Return values
array

get_address_formats()

Get country address formats.

public get_address_formats() : array

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

Return values
array

get_allowed_countries()

Get countries that the store sells to.

public get_allowed_countries() : array
Return values
array

get_allowed_country_states()

Get allowed country states.

public get_allowed_country_states() : array
Return values
array

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_country_calling_code()

Get calling code for a country code.

public get_country_calling_code(string $cc) : string|array
Parameters
$cc : string

Country code.

Tags
since
3.6.0
Return values
string|arraySome 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

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

Return values
array

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
Return values
array

get_default_address_fields()

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

public get_default_address_fields() : array
Return values
array

get_european_union_countries()

Gets an array of countries in the EU.

public get_european_union_countries([string $type = '' ]) : string[]
Parameters
$type : string = ''

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

Return values
string[]

get_formatted_address()

Get country address format.

public get_formatted_address([array $args = array() ][, string $separator = '<br/>' ]) : string
Parameters
$args : array = 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
Tags
since
3.6.0
Return values
array

get_shipping_countries()

Get countries that the store ships to.

public get_shipping_countries() : array
Return values
array

get_shipping_country_states()

Get shipping country states.

public get_shipping_country_states() : array
Return values
array

get_states()

Get the states for a country.

public get_states([string $cc = null ]) : false|array
Parameters
$cc : string = null

Country code.

Return values
false|arrayof states

get_vat_countries()

Gets an array of countries using VAT.

public get_vat_countries() : string[]
Tags
since
4.0.0
Return values
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