Country Select
country_select outputs an HTML <select> of countries from CartThrob locales data.
To edit country lists, see Locales Config.
See also:
Parameters
name
Name attribute of the generated <select>.
Default: country.
name="country_code"
selected
Currently selected country value.
selected="USA"
default
Fallback selected value when selected is not provided.
default="USA"
orderby
Sort order mode for options.
Default: name (sort by country name).
Any non-name value sorts by option key/value code.
orderby="name"
orderby="code"
alpha2
When country codes are enabled, use alpha-2 codes instead of alpha-3 codes for option values.
alpha2="yes"
country_codes
Controls whether option values are country codes or country names.
Default: yes (code values).
no uses country names as option values.
country_codes="yes"
country_codes="no"
id
id attribute for the <select>.
id="country_code"
class
class attribute for the <select>.
class="country-select"
onchange
Inline JavaScript onchange attribute.
onchange="this.form.submit()"
extra
Additional raw HTML attributes appended to the <select>.
extra='data-role="country-select"'
add_blank
Adds a blank --- option at the top.
add_blank="yes"
Output
Returns an HTML <select> element.
Option values depend on country_codes and alpha2:
country_codes="yes"+alpha2="no"(default): values are alpha-3 codes (for exampleUSA).country_codes="yes"+alpha2="yes": values are alpha-2 codes (for exampleUS).country_codes="no": values are country names.
Behavior and Constraints
- Country list comes from
ee()->locales->countries(alpha2, country_codes). - Locale filtering (
cartthrob:locales_countries) can limit which countries are included. selectedtakes precedence;defaultis used only as fallback.- Sorting defaults to name (
orderby="name"); otherwise keys/codes are sorted. id,class,onchange, andextraare passed through to the generated<select>.
Examples
Basic usage:
{exp:cartthrob:country_select name="country_code" selected="{customer_country_code}"}
Save/update country in a form:
{exp:cartthrob:save_customer_info_form return="cart/view_cart"}
{exp:cartthrob:country_select name="country_code" selected="{customer_country_code}"}
<input type="submit" value="Update Your Country" />
{/exp:cartthrob:save_customer_info_form}
Use alpha-2 code values and a blank option:
{exp:cartthrob:country_select
name="shipping_country_code"
alpha2="yes"
add_blank="yes"
selected="{customer_shipping_country_code}"
}