Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-02T15:51:45.313Z
Answers.Text: Thanks! But will this actually work with the tax rates and shipping methods? Asking for a friend 
Answers.UserDisplayName: outline4
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-02T16:10:33.077Z
Answers.Text: I've updated the question above. it uses ´craft.commerce.countriesList´. how, in this case, would the option values and error messages look like?
Answers.UserDisplayName: outline4
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-03T00:26:10.237Z
Answers.Text: Why use `craft.commerce.countriesList`?  It's going to be a lot more inefficient than just going through `craft.commerce.countries` directly.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-03T09:04:56.920Z
Answers.Text: 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?
Answers.UserDisplayName: outline4
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-03T09:08:12.513Z
Answers.Text: I've updated the answer to better reflect where we are...
Answers.UserDisplayName: outline4
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-03T09:16:25.890Z
Answers.Text: so the whole thing comes down to: could I use `<option value="{{ country.iso }}">`... over `<option value="{{ country.id }}">`
Answers.UserDisplayName: outline4
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-03T09:47:03.750Z
Answers.Text: @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
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-08T13:20:42.963Z
Answers.Text: craft.commerce.countries outputs nothing for me in 2.1.7. Needs to be craft.commerce.countries.allCountries.
Answers.UserDisplayName: Laurence Cope
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-02T14:44:36.580Z
Answers.LastActivityDate: 2018-03-02T14:44:36.580Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-02T12:44:10.930Z
Comments.Text: Have you tried dumping the `option`-variable inside your for-loop to see if it contains a reference to a country-code?
Comments.UserDisplayName: Fuglsetrampen
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-03T14:00:21.900Z
Comments.Text: Hi Fuglsetrampen, could you maybe elaborate on how to dump the option variable?
Comments.UserDisplayName: outline4
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-05T07:58:08.513Z
Comments.Text: 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.
Comments.UserDisplayName: Fuglsetrampen
Tags: <plugin-craftcommerce>
Title: Commerce: Is there a way to use a countries dropdown with iso codes (US, CH etc) instead of ids?
ThreadText: # 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:
  
  ```html
  <form method="POST" accept-charset="UTF-8" class="ui form validate">
      {{ getCsrfInput() }}
      <input type="hidden" name="action" value="commerce/cart/updateCart" />
  
      [...]
  
      {% set countries = craft.commerce.countries %}
      {% if countries|length > 1 %}
          <div class="field{% if model and model.getErrors('countryId') %} error{% endif %}">
              <label>{{ "Country"|t }}</label>
              <select name="{{ modelName }}[countryId]" class="ui fluid dropdown">
                  <option value="">{{ "Choose Country"|t }}</option>
                  {% for country in countries %}
                      {% set optionValue = (model ? model.countryId : '') %}
                      <option value="{{ country.id }}"{% if country.id == optionValue %} selected="selected"{% endif %}>{{ country.name }}</option>
                      <div class="item" data-value="">{{ country.name }}</div>
                  {% endfor %}
              </select>
              {% if model and model.getErrors('countryId') %}
                  <span class="error">{{ model.getErrors('countryId')|join }}</span>
              {% endif %}
          </div>
      {% endif %}
  
      [...]
  
  </form>
  
  ```
  
  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 %}
  
  <ul>
  {% for country in countries %}
      <li>{{ country.iso }}</li>
  {% endfor %}
  </ul>
  
  ```
  
  > **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.  
  
  ---
  
  