<p>This should do it:</p>

<pre><code>{% set countries = craft.commerce.countries %}

&lt;ul&gt;
{% for country in countries %}
    &lt;li&gt;{{ country.iso }}&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;
</code></pre>

CC BY-SA 3.0
2018-03-02T15:51:45.313Z
Thanks! But will this actually work with the tax rates and shipping methods? Asking for a friend 
outline4
CC BY-SA 3.0
2018-03-02T16:10:33.077Z
I've updated the question above. it uses ´craft.commerce.countriesList´. how, in this case, would the option values and error messages look like?
outline4
CC BY-SA 3.0
2018-03-03T00:26:10.237Z
Why use `craft.commerce.countriesList`?  It's going to be a lot more inefficient than just going through `craft.commerce.countries` directly.
Brad Bell
CC BY-SA 3.0
2018-03-03T09:04:56.920Z
Hi, I am not trying to output only a countries list. I was asking if it is possible to use the ISO value vs. the ID of a country within the checkout process. Turns out, that you'll have to use the country ID in checkout? It just won't accept the country code, or am I wrong?
outline4
CC BY-SA 3.0
2018-03-03T09:08:12.513Z
I've updated the answer to better reflect where we are...
outline4
CC BY-SA 3.0
2018-03-03T09:16:25.890Z
so the whole thing comes down to: could I use `<option value="{{ country.iso }}">`... over `<option value="{{ country.id }}">`
outline4
CC BY-SA 3.0
2018-03-03T09:47:03.750Z
@outline4 I know this might sound a little bit dump but why don't you just try it out. You asked this question whether it is possible or not so you came to the idea that there might be a way. You can change the value, go to the controller and `var_dump` & `die` before the paying process or set your paying service as sandbox. If you had used the `{{dump(country)}}` function in twig you would have noticed there is a `iso` attribute from the beginning. Just for future reference: Crafts documentation is mainly in the source code. If you don't want to ask everything here you need to find things out
Robin Schambach
CC BY-SA 4.0
2019-07-08T13:20:42.963Z
craft.commerce.countries outputs nothing for me in 2.1.7. Needs to be craft.commerce.countries.allCountries.
Laurence Cope
CC BY-SA 3.0
2018-03-02T14:44:36.580Z
2018-03-02T14:44:36.580Z
Brad Bell
<p>Here's some code from Craft Commerce's examples:</p>

<pre class="lang-html prettyprint-override"><code>&lt;form method="POST" accept-charset="UTF-8" class="ui form validate"&gt;
    {{ getCsrfInput() }}
    &lt;input type="hidden" name="action" value="commerce/cart/updateCart" /&gt;

    [...]

    {% set countries = craft.commerce.countries %}
    {% if countries|length &gt; 1 %}
        &lt;div class="field{% if model and model.getErrors('countryId') %} error{% endif %}"&gt;
            &lt;label&gt;{{ "Country"|t }}&lt;/label&gt;
            &lt;select name="{{ modelName }}[countryId]" class="ui fluid dropdown"&gt;
                &lt;option value=""&gt;{{ "Choose Country"|t }}&lt;/option&gt;
                {% for country in countries %}
                    {% set optionValue = (model ? model.countryId : '') %}
                    &lt;option value="{{ country.id }}"{% if country.id == optionValue %} selected="selected"{% endif %}&gt;{{ country.name }}&lt;/option&gt;
                    &lt;div class="item" data-value=""&gt;{{ country.name }}&lt;/div&gt;
                {% endfor %}
            &lt;/select&gt;
            {% if model and model.getErrors('countryId') %}
                &lt;span class="error"&gt;{{ model.getErrors('countryId')|join }}&lt;/span&gt;
            {% endif %}
        &lt;/div&gt;
    {% endif %}

    [...]

&lt;/form&gt;
</code></pre>

<p>I wonder if it's somehow possible to work with the country code (e.g. US, CH...) instead of the country id of Craft Commerce (1..256). So basically, countryId vs. countryIso? </p>

<p>I can't find any information in the docs. </p>

<p>It might be a small detail, but when using form autofill with programs like 1password, it won't be able to fill in the country automatically when using an id vs. a country code. </p>

CC BY-SA 3.0
2018-03-02T12:44:10.930Z
Have you tried dumping the `option`-variable inside your for-loop to see if it contains a reference to a country-code?
Fuglsetrampen
CC BY-SA 3.0
2018-03-03T14:00:21.900Z
Hi Fuglsetrampen, could you maybe elaborate on how to dump the option variable?
outline4
CC BY-SA 3.0
2018-03-05T07:58:08.513Z
Dumping something is as easy as `{{ dump(option) }}` (inside the for-loop in your case). Now, what I would probably do in your situation (based on the updated / rewritten question) is: Give my select a "bogus" name, print the ISO-code as the value of the options, print the ID as a data-attribute of the options, have a hidden [countryId]-field, use JS to update the value of my hidden field based on the data-attribute of the selected option in a event-handler.
Fuglsetrampen
<plugin-craftcommerce>
Commerce: Is there a way to use a countries dropdown with iso codes (US, CH etc) instead of ids?
# Commerce: Is there a way to use a countries dropdown with iso codes (US, CH etc) instead of ids?

(Asked by: username_0 on 2018-03-01)

Here's some code from Craft Commerce's examples:

    {{ getCsrfInput() }}
    

    [...]

    {% set countries = craft.commerce.countries %}
    {% if countries|length > 1 %}
        
            {{ "Country"|t }}
            
                {{ "Choose Country"|t }}
                {% for country in countries %}
                    {% set optionValue = (model ? model.countryId : '') %}
                    {{ country.name }}
                    {{ country.name }}
                {% endfor %}
            
            {% if model and model.getErrors('countryId') %}
                {{ model.getErrors('countryId')|join }}
            {% endif %}
        
    {% endif %}

    [...]



I wonder if it's somehow possible to work with the country code (e.g. US, CH...) instead of the country id of Craft Commerce (1..256). So basically, countryId vs. countryIso? 
I can't find any information in the docs. 
It might be a small detail, but when using form autofill with programs like 1password, it won't be able to fill in the country automatically when using an id vs. a country code.

**Tags:** plugin-craftcommerce

> **Comments:**
> **username_1**: Have you tried dumping the `option`-variable inside your for-loop to see if it contains a reference to a country-code?  
> **username_0**: Hi username_1, could you maybe elaborate on how to dump the option variable?  
> **username_1**: Dumping something is as easy as `{{ dump(option) }}` (inside the for-loop in your case). Now, what I would probably do in your situation (based on the updated / rewritten question) is: Give my select a "bogus" name, print the ISO-code as the value of the options, print the ID as a data-attribute of the options, have a hidden [countryId]-field, use JS to update the value of my hidden field based on the data-attribute of the selected option in a event-handler.  

---

## 1 answers

### Answer by username_2 on 2018-03-02. Score: 1

This should do it:
{% set countries = craft.commerce.countries %}


{% for country in countries %}
    {{ country.iso }}
{% endfor %}

> **Comments:**
> **username_0**: Thanks! But will this actually work with the tax rates and shipping methods? Asking for a friend   
> **username_0**: I've updated the question above. it uses ´craft.commerce.countriesList´. how, in this case, would the option values and error messages look like?  
> **username_2**: Why use `craft.commerce.countriesList`?  It's going to be a lot more inefficient than just going through `craft.commerce.countries` directly.  
> **username_0**: Hi, I am not trying to output only a countries list. I was asking if it is possible to use the ISO value vs. the ID of a country within the checkout process. Turns out, that you'll have to use the country ID in checkout? It just won't accept the country code, or am I wrong?  
> **username_0**: I've updated the answer to better reflect where we are...  
> **username_0**: so the whole thing comes down to: could I use `<option value="{{ country.iso }}">`... over `<option value="{{ country.id }}">`  
> **username_3**: @username_0 I know this might sound a little bit dump but why don't you just try it out. You asked this question whether it is possible or not so you came to the idea that there might be a way. You can change the value, go to the controller and `var_dump` & `die` before the paying process or set your paying service as sandbox. If you had used the `{{dump(country)}}` function in twig you would have noticed there is a `iso` attribute from the beginning. Just for future reference: Crafts documentation is mainly in the source code. If you don't want to ask everything here you need to find things out  
> **username_4**: craft.commerce.countries outputs nothing for me in 2.1.7. Needs to be craft.commerce.countries.allCountries.  

---

