I'm working on a new checkout process which involves taking the shipping address first.

To do this I am setting sameAddress to 1 in my shippingAddress form.

Then, at a later stage I want to offer the customer the option to change their billing address. I thought I could just present the customer with a new form for billingAddress fields and set sameAddress to 0, or false.

However, this doesn't seem to let me override the already stored billing address. It seems that once sameAddress is set, it cannot be unset.

I have tried setting a hidden billing address when setting the shipping address but again it's not letting me override that later.

Is there way I can achieve this checkout flow?

Shipping address info -> shipping method selection -> payment (with option to use a different address for billing)?

up vote 1 down vote accepted

It is possible to override sameAddress

The trick to doing this is as follows:

Checkout Step 1: Set your shipping address and use sameAddress1

<form method="POST">
    <input type="hidden" name="action" value="commerce/cart/updateCart">
    <input type="hidden" name="redirect" value="/checkout/shipping">
    <input type="hidden" name="shippingAddressId" value="new">
    <input type="hidden" name="sameAddress" value="1">

      shipping address fields here        

</form>

Checkout Step 2: Set shipping method as normal

Checkout Step 3: Set the billing address, including the shipping address as hidden fields, set sameAddress to 0.

<form method="POST" id="paymentMethod">
    <input type="hidden" name="action" value="commerce/cart/updateCart">
    <input type="hidden" name="redirect" value="/checkout/payment">

    <!-- billing fields -->
    <input type="text" name="billingAddress[firstName]" value="{{ cart.billingAddress ? cart.billingAddress.firstName }}">
    <input type="text" name="billingAddress[lastName]" value="{{ cart.billingAddress ? cart.billingAddress.lastName }}">

    etc.
    <!-- tell Craft this is a new billing address -->
    <input type="hidden" name="billingAddressId" value="new">

    <!-- hidden shipping address fields -->
    <input type="hidden" name="shippingAddress[firstName]" value="{{ cart.shippingAddress.firstName }}">
    <input type="hidden" name="shippingAddress[lastName]" value="{{ cart.shippingAddress.lastName }}">

    etc.
</form>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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