Answers.Body: <p>Craft 5.3 and 4.11 added a <code>getCountry()</code> method to address elements. This method returns a <code>CommerceGuys\Addressing\Country\Country</code> model, which (among other things) has a <code>name</code> property that can be used to access the country's full name:</p>
  <p>In Twig:</p>
  <pre><code>{% set country = entry.someAddressField.one().country.name|default %}
  </code></pre>
  <p>PHP:</p>
  <pre class="lang-php prettyprint-override"><code>$country = $entry-&gt;someAddressField-&gt;one()?-&gt;getCountry()-&gt;name;
  </code></pre>
  <p>Check out <a href="https://craftcms.com/docs/5.x/reference/element-types/addresses.html#country-names" rel="nofollow noreferrer">the official docs</a> or <a href="https://github.com/craftcms/cms/pull/15463" rel="nofollow noreferrer">the original PR</a> for more details.</p>
  <p><em>Note that for Craft 4 and 5 versions earlier than 5.3 or 4.11, Steve Holland's answer works.</em></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-04T22:09:48.680Z
Answers.LastActivityDate: 2024-08-07T09:16:44.823Z
Answers.LastEditDate: 2024-08-07T09:16:44.823Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <p>You'd need to call the Country Repository to fetch the Country itself. I found it in the Craft v4 docs <a href="https://craftcms.com/docs/commerce/4.x/countries-states.html#country-by-id" rel="nofollow noreferrer">here</a>. I'm assuming it'd be the same for Craft v5</p>
  <p>Twig</p>
  <pre><code>{# @var country CommerceGuys\Addressing\Country\Country #}
  {% set country = craft.app.getAddresses().countryRepository.get('US') %}
  </code></pre>
  <p>PHP</p>
  <pre><code>/** @var CommerceGuys\Addressing\Country\Country $country **/
  $country = Craft::$app-&gt;getAddresses()-&gt;countryRepository-&gt;get('US');
  </code></pre>
  <p>Just replace 'US' with your <code>countryCode</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-02T08:59:42.957Z
Answers.LastActivityDate: 2024-08-02T08:59:42.957Z
Answers.UserDisplayName: Steve Holland
Body: <p>I'm using the Address field in Craft CMS 5, as detailed in the <a href="https://craftcms.com/docs/5.x/reference/element-types/addresses.html" rel="nofollow noreferrer">Craft CMS documentation</a>. I need to display the full country name based on the <code>countryCode</code> provided by the Address field.</p>
  <p>Currently, the Address field only provides a <code>countryCode</code>, and it seems there is no direct way to get the full country name. I understand I could use a lookup table or a plugin, but I'm looking for a solution that doesn't require either of these.</p>
  <p>Why does Craft CMS 5 only provide the <code>countryCode</code> and not a <code>country</code> attribute that directly gives the full country name? Is there an existing native method or a built-in function in Craft CMS that can convert the <code>countryCode</code> to the full country name without resorting to external resources?</p>
  
Tags: <addresses>
Title: How to retrieve full country name from address field
ThreadText: # How to retrieve full country name from address field
  
  (Asked by: username_0 on 2024-08-01)
  
  I'm using the Address field in Craft CMS 5, as detailed in the [Craft CMS documentation](https://craftcms.com/docs/5.x/reference/element-types/addresses.html). I need to display the full country name based on the `countryCode` provided by the Address field.
  
  Currently, the Address field only provides a `countryCode`, and it seems there is no direct way to get the full country name. I understand I could use a lookup table or a plugin, but I'm looking for a solution that doesn't require either of these.
  
  Why does Craft CMS 5 only provide the `countryCode` and not a `country` attribute that directly gives the full country name? Is there an existing native method or a built-in function in Craft CMS that can convert the `countryCode` to the full country name without resorting to external resources?
  
  **Tags:** addresses
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2024-08-04. Score: 2 | Accepted answer
  
  Craft 5.3 and 4.11 added a `getCountry()` method to address elements. This method returns a `CommerceGuys\Addressing\Country\Country` model, which (among other things) has a `name` property that can be used to access the country's full name:
  
  In Twig:
  
  ```
  {% set country = entry.someAddressField.one().country.name|default %}
  
  ```
  
  PHP:
  
  ```php
  $country = $entry->someAddressField->one()?->getCountry()->name;
  
  ```
  
  Check out [the official docs](https://craftcms.com/docs/5.x/reference/element-types/addresses.html#country-names) or [the original PR](https://github.com/craftcms/cms/pull/15463) for more details.
  
  *Note that for Craft 4 and 5 versions earlier than 5.3 or 4.11, username_2's answer works.*
  
  
  ---
  
  ### Answer by username_2 on 2024-08-02. Score: 3
  
  You'd need to call the Country Repository to fetch the Country itself. I found it in the Craft v4 docs [here](https://craftcms.com/docs/commerce/4.x/countries-states.html#country-by-id). I'm assuming it'd be the same for Craft v5
  
  Twig
  
  ```
  {# @var country CommerceGuys\Addressing\Country\Country #}
  {% set country = craft.app.getAddresses().countryRepository.get('US') %}
  
  ```
  
  PHP
  
  ```
  /** @var CommerceGuys\Addressing\Country\Country $country **/
  $country = Craft::$app->getAddresses()->countryRepository->get('US');
  
  ```
  
  Just replace 'US' with your `countryCode`.
  
  
  ---
  
  