1

Folks, this has to be easier than I've made it. In a front-end template, how do you grab a state abbreviation from a customer's address in Craft Commerce?

{$ set addresses = craft.commerce.customer.addresses $}
{% for address in addresses %}
  <-- this is where I want to show the abbreviation -->
  {{ address.state.abbreviation }}
{% endfor %}
1

I received an answer on Slack from Stephen Callendar.

{% set addresses = craft.commerce.customer.addresses %}
{% for address in addresses %}
  {% if address.getState() %}
    {{ address.getState().abbreviation }}
  {% endif %}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.