Displaying the Default Address as the first address on the All Addresses Page

coding_beginner
Shopify Partner
5 0 1
Hello!
I'm currently working on a page that displays every address the user has saved to their account.
This page utilizes pagination once the user saves more than 4 addresses, but I'm having trouble automatically listing the user's default address as the first item on the list.
Below is the code I'm using:
{% paginate customer.addresses by 4 %}
  {% for address in customer.addresses %}
    ** Code **
  {% endfor %}
{% endpaginate %}
I've tried including customer.addresses | sort: 'default' but it doesn't seem to work.
Any advise or help would be greatly appreciated.
Thanks in advance!
Replies 2 (2)

Rishihuptech
Shopify Partner
351 63 68

Hi @coding_beginner 
You can use the code below to show the default address first

{% for address in customer.addresses %}
{% if address == customer.default_address %}
{{ address | format_address }}
{% else %}
{{ address | format_address }}
{% endif %}
{% endfor %}

 

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
coding_beginner
Shopify Partner
5 0 1

Hello!
Thank you for you reply!
Unfortunately, applying the code displays the same results.
I currently have JANE465 DOE set as the default address, but it's second in the address list (Image included).

coding_beginner_0-1701226031058.png