States
states is a tag pair that loops through state/province rows from CartThrob locales and outputs abbreviation + name variables.
By default, it uses the configured default state country. You can also target one or more countries directly with country_code.
To edit the list of states that are used, see Locales Config.
See also:
Parameters
country_code
Country code used to choose which state/province set is returned.
Format:
- single code:
USA - multiple codes with pipes:
USA|CAN
If omitted, CartThrob uses the configured default state country.
country_code="USA"
country_code="USA|CAN"
Variables
abbrev
Prints the state’s two-letter abbreviation.
{abbrev}
state
Prints the state’s full name.
{state}
Behavior and Constraints
- This is a looping tag pair; output comes from the tag body.
- Data source is
ee()->locales->states($country_code). country_codeaccepts pipe-delimited values; matching state lists are merged in order.- If no matching states exist for the provided country code(s), the loop returns no rows.
- This tag does not apply additional sorting/formatting parameters by itself.
Examples
Default list (uses configured default state country):
<select name="state">
{exp:cartthrob:states}
<option value="{abbrev}">{state}</option>
{/exp:cartthrob:states}
</select>
USA only:
<select name="state">
{exp:cartthrob:states country_code="USA"}
<option value="{abbrev}">{state}</option>
{/exp:cartthrob:states}
</select>
USA + Canada:
{exp:cartthrob:states country_code="USA|CAN"}
{abbrev} - {state}<br>
{/exp:cartthrob:states}