How can I allow customers to set their default address?

I was wondering how I can allow my customers to easily set their default address on customer addresses page.

I am using Dawn theme and as its default, customers can set their default address from address edit form (there is a checkbox for setting a default address).

But I would like to make it easier to do that by like adding a button “Set as default address” under each non-default address list.

How could I achieve that?

1 Like

To add a “Set as default address” button under each non-default address list on the customer addresses page in your Shopify store, you will need to modify the theme’s template files. Here are the steps you can follow:

  1. Go to the “Online store” section of your Shopify admin and click on “Themes.”

  2. Click on the “Actions” button next to the theme you are using and select “Edit code.”

  3. In the “Templates” directory, look for the file named “customer/addresses.liquid.” This is the template file that controls the layout and content of the customer addresses page.

  4. Scroll down to the section where the customer’s addresses are displayed. You will see a loop that iterates over the customer’s addresses and outputs each one.

  5. Inside the loop, you will need to add a new element that submits a request to update the customer’s default address. Here is an example of what the form might look like:


  • Save your changes and publish the theme. The “Set as default address” button should now be displayed under each non-default address on the customer addresses page.

I hope this helps! If you want I can do that for you !

1 Like

Thank you so much for your answer!

I tried the code above but it gives me 404 error…

Do I have to use address form tag or something?

Look for the section of the template that loops through the customer’s addresses and displays them on the page. It will look something like this:

{% for address in customer.addresses %}
{% if address.default == false %}
  
{% endif %}
{% endfor %}

It will fetch and display all the addresses and if default address is not selected it will show a button.

Now, when a customer visits the customer addresses page, they will see a “Set as default” button for each non-default address. When they click the button, the form will be submitted and the address with the corresponding ID will be set as the default address.

Keep in mind that this is just a basic example of how you could add a “Set as default” button to the customer addresses page. You may need to customize the code further to match the design and functionality of your store.

For example, you may want to add some JavaScript to update the page after the form is submitted, or add some error handling in case the form submission fails.

Well…

I still got 404 error.

I think the path on action attribute is wrong.

(I understand how to loop addresses and if-condition.)

I just wanted to know correct form values to set a default address.

I figured out how to add “Set as default” button and function to address list by looking at the doc here about “form.set_as_default_checkbox”.

{%- for address in customer.addresses -%}

 {%- form 'customer_address', address -%}
   
   
 {%- endform -%}
{%- endfor -%}

I hope this helps others who are trying to do the same as me.

1 Like