Update customer default address from Cart

Update customer default address from Cart

rfrauzino
Shopify Partner
7 0 1

Some of our clients have multiple addresses on their account, and I'm looking to create a simple way for them to select which address to use on checkout from the cart page, rather than going back to account > addresses for every purchase.

 

My idea is to use a radio button group for the customer's addresses, but I'm not sure how to translate the selected address to the customer object and actually change the default address, or how to use the selected address for checkout.

 

Here is the code I've injected into the cart page so far:

 

 

{% if customer and customer.addresses_count > 1 %}
                <div class="address-select">
                  <h4>Select Address</h4>
                  <form class="address-select-form">
                    {% for address in customer.addresses %}
                      <div class="radio-select">
                        <label for="{{ address.name }}-{{ forloop.index }}">
                          {{ address.name }}
                        </label>
                        <input 
                          type="radio"
                          name="addresses"
                          id="{{ address.name }}-{{ forloop.index }}"
                          value="{{ address }}"
                          {% if address == customer.default_address %}
                            checked
                          {% endif %}
                        >
                      </div>
                    {% endfor %}
                  </form>
                </div>
              {% endif %}

 

Reply 1 (1)

PaulNewton
Shopify Partner
7746 679 1613

Your html form isn't submitting to anything.

Just reference the customer address form tag in the theme , replicate it then pare it down to the minimum needed.

Also see the docs https://shopify.dev/docs/themes/architecture/templates/customers-addresses 

 

If you need this customization done for you then contact me by mail for services.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.
Contact info in signature.

 

Good Hunting.

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org