<p><a href="https://craftcommerce.com/docs/update-cart-addresses#summary" rel="nofollow noreferrer">Docs</a></p>

<blockquote>
  <p>As you can see from both examples, the <strong>shipping address</strong> is <strong>always</strong> submitted, and the <strong>billingAddress</strong> can either be also included, or set to the same address as the shipping address with the sameAddress param.</p>
</blockquote>

<p>The shippings address is always submitted -> the billing address can be included or not </p>

<p>Your statement:</p>

<blockquote>
  <p>At the bottom is a checkmark which by default sets the shipping address to be the same as the billing address. This however does not work.</p>
</blockquote>

<p>You set the <strong>shipping address</strong> like <strong>billing address</strong> which is the other way around and won't work unless you change the logic</p>

CC BY-SA 3.0
2018-01-04T13:04:05.083Z
Thanks Robin. So if I follow you correctly I should swap them and ask for a billing address first and then have a toggle that asks "Use same address for shipping"? Is that what you mean?
patrick.altair
CC BY-SA 3.0
2018-01-04T13:15:06.000Z
I've just tried swapping them Robin (asking for the billing first) but the problem persists. Hmmm
patrick.altair
CC BY-SA 3.0
2018-01-04T14:03:45.690Z
You said you set the shipping address to the billing address and that's not going to work (like I posted) now in your comment you say "I swap them and ask for the billing address first" which is the same like your first approach. You must check for the shipping address. You NEED the shipping address, the billing address is optional. You can set the billing address to the shipping address
Robin Schambach
CC BY-SA 3.0
2018-01-04T16:14:58.927Z
Oh I'm sorry Robin I wasn't being clear. I've posted the full code of the form to the post now so you can see. I'm asking for the shipping address first, then electively giving the user the option to put in a different billing address if they want. If the user leaves the "Use same address for billing" box ticked though it doesn't work.
patrick.altair
CC BY-SA 3.0
2018-01-04T16:27:21.853Z
Could you please explain that a little bit further? Does the billing address keeps the same as before? Does it become blank? You could check the file `Commerce_CartController.php` line 222 `$result = craft()->commerce_orders->setOrderAddresses($cart, $shippingAddress, $shippingAddress);` and include a `var_dump` if this statement is reached. This stores the shipping address as your billing address. You can check your `$sameAddress` parameter as well if its the correct value
Robin Schambach
CC BY-SA 3.0
2018-01-04T17:10:31.500Z
Ok, I just got it working. I changed tack, since the hidden Billing Address forms appeared to be causing the problem I moved them to a separate billing.html  and then used ajax to load in billing.html when the "Use same address for billing" was turned off. I appreciate all your effort though, Robin. Helps just to talk a problem through with someone!
patrick.altair
CC BY-SA 3.0
2018-01-04T17:14:40.053Z
Ahh no I found the real problem. I did not expect this to happen since its common sense... You named your checkbox and your hidden field equal. That was causing the problem names should be unique in a form if it's not an array
Robin Schambach
CC BY-SA 3.0
2018-01-04T07:40:25.497Z
2018-01-04T07:40:25.497Z
Robin Schambach
<p>I have a checkout page where a user puts in their shipping address. At the bottom is a checkmark which by default sets the shipping address to be the same as the billing address. This however does not work.</p>

<pre><code>&lt;input type="hidden" name="sameAddress" class="sameAddressValue" value="1"&gt;

&lt;div class="use-same-address"&gt;
  &lt;label for="sameAddress"&gt;&lt;input id="sameAddress" name="sameAddress" type="checkbox" checked="checked"/&gt;
    &lt;span class="label-body"&gt;Use same address for billing&lt;/span&gt;
  &lt;/label&gt;
&lt;/div&gt;
</code></pre>

<p>If the checkmark is unchecked the sameAddress value is set to 0, the billing address fields appear and you can type in a different billing address. This does work.</p>

<p>I'm using sameAddress = 1 as advised in the documentation but it doesn't seem to work. Here's the relevant js that toggles the billing address and same address value. Is hiding he billing address fields causing some sort of error?</p>

<pre><code>    $("#sameAddress").change(function (e) {
        $('.billingAddress').toggleClass('hidden');
        if (this.checked) {
            $('.required-toggle').removeAttr('required');
            $('.sameAddressValue').val(1);
        } else{
            $('.required-toggle').attr('required', '');
            $('.sameAddressValue').val(0);
        }
    });
</code></pre>

<p><strong>Edit:</strong> Adding all the form code</p>

<pre><code>&lt;form method="post"&gt;

        &lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;
        &lt;input type="hidden" name="redirect" value="shop/checkout/payment"/&gt;

        {{ getCsrfInput() }}

        &lt;h3&gt;Delivery address&lt;/h3&gt;

        &lt;div class="half-width"&gt;
            &lt;div class="field"&gt;
                &lt;label for="shippingAddress-firstName"&gt;First Name&lt;/label&gt;
                &lt;input type="text" id="shippingAddress-firstName" name="shippingAddress[firstName]" pattern=".{2,}" required value=""&gt;
            &lt;/div&gt;

            &lt;div class="field"&gt;
                &lt;label for="shippingAddress-lastName"&gt;Last Name&lt;/label&gt;
                &lt;input type="text" id="shippingAddress-lastName" name="shippingAddress[lastName]" required value=""&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;div class="field  clear"&gt;
            &lt;label for="shippingAddress-businessName"&gt;Company (optional)&lt;/label&gt;
            &lt;input type="text" id="shippingAddress-businessName" name="shippingAddress[businessName]" value=""&gt;
        &lt;/div&gt;

        &lt;div class="field  clear"&gt;
            &lt;label for=""&gt;Email&lt;/label&gt;
            &lt;input type="text" value="{{ cart.email }}" name="email" required placeholder="example@site.com"/&gt;
        &lt;/div&gt;

        &lt;div class="field  clear"&gt;
            &lt;label for="shippingAddress-phone"&gt;Phone&lt;/label&gt;
            &lt;input type="text" id="shippingAddress-phone" class="u-full-width" placeholder="020 7946 0123" name="shippingAddress[phone]" required value=""&gt;
        &lt;/div&gt;


        &lt;div class="field clear"&gt;
            &lt;label for="shippingAddress-address1"&gt;Address 1&lt;/label&gt;
            &lt;input type="text" id="shippingAddress-address1" name="shippingAddress[address1]" required value=""&gt;
        &lt;/div&gt;

        &lt;div class="field clear"&gt;
            &lt;label for="shippingAddress-address2"&gt;Address 2&lt;/label&gt;
            &lt;input type="text" id="shippingAddress-address2" name="shippingAddress[address2]" value=""&gt;
        &lt;/div&gt;

        &lt;div class="half-width"&gt;
            &lt;div class="field"&gt;
                &lt;label for="shippingAddress-city"&gt;City&lt;/label&gt;
                &lt;input type="text" id="shippingAddress-city" name="shippingAddress[city]" required value=""&gt;
            &lt;/div&gt;

            &lt;div class="field"&gt;
                &lt;label for="shippingAddress-postCode"&gt;Post Code&lt;/label&gt;
                &lt;input type="text" id="shippingAddress-postCode" name="shippingAddress[postCode]" maxlength="8" required value=""&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;div class="field clear"&gt;
            &lt;label for="shippingAddress-countryId"&gt;Country&lt;/label&gt;
            &lt;select class="address-country u-full-width form-control input-sm" id="shippingAddress-countryId" name="shippingAddress[countryId]"&gt;
                &lt;option value="77"&gt;United Kingdom&lt;/option&gt;
            &lt;/select&gt;
        &lt;/div&gt;

        {# Use same address button #}
        &lt;input type="hidden" name="sameAddress" class="sameAddressValue" value="1"&gt;
        &lt;div class="use-same-address"&gt;
            &lt;label for="sameAddress"&gt;&lt;input id="sameAddress" name="sameAddress" type="checkbox" checked="checked"/&gt;&lt;span class="label-body"&gt;Use same address for
        billing&lt;/span&gt;&lt;/label&gt;
        &lt;/div&gt;

        &lt;div class="billingAddress hidden"&gt;
            &lt;h3&gt;Billing address&lt;/h3&gt;

            &lt;div class="half-width"&gt;
                &lt;div class="field"&gt;
                    &lt;label for="billingAddress-firstName"&gt;First Name&lt;/label&gt;
                    &lt;input class="required-toggle" type="text" id="billingAddress-firstName" name="billingAddress[firstName]" value=""&gt;
                &lt;/div&gt;

                &lt;div class="field"&gt;
                    &lt;label for="billingAddress-lastName"&gt;Last Name&lt;/label&gt;
                    &lt;input class="required-toggle" type="text" id="billingAddress-lastName" name="billingAddress[lastName]" value=""&gt;
                &lt;/div&gt;
            &lt;/div&gt;

            &lt;div class="field  clear"&gt;
                &lt;label for="billingAddress-businessName"&gt;Company (optional)&lt;/label&gt;
                &lt;input type="text" id="billingAddress-businessName" name="billingAddress[businessName]" value=""&gt;
            &lt;/div&gt;

            &lt;div class="field  clear"&gt;
                &lt;label for=""&gt;Email&lt;/label&gt;
                &lt;input class="required-toggle" type="text" value="{{ cart.email }}" name="email" placeholder="email@site.com"/&gt;
            &lt;/div&gt;

            &lt;div class="field  clear"&gt;
                &lt;label for="billingAddress-phone"&gt;Phone&lt;/label&gt;
                &lt;input class="required-toggle" type="text" id="billingAddress-phone" class="u-full-width" name="billingAddress[phone]" value=""&gt;
            &lt;/div&gt;


            &lt;div class="field clear"&gt;
                &lt;label for="billingAddress-address1"&gt;Address 1&lt;/label&gt;
                &lt;input class="required-toggle" type="text" id="billingAddress-address1" name="billingAddress[address1]" value=""&gt;
            &lt;/div&gt;

            &lt;div class="field clear"&gt;
                &lt;label for="billingAddress-address2"&gt;Address 2&lt;/label&gt;
                &lt;input type="text" id="billingAddress-address2" name="billingAddress[address2]" value=""&gt;
            &lt;/div&gt;

            &lt;div class="half-width"&gt;
                &lt;div class="field"&gt;
                    &lt;label for="billingAddress-city"&gt;City&lt;/label&gt;
                    &lt;input class="required-toggle" type="text" id="billingAddress-city" name="billingAddress[city]" value=""&gt;
                &lt;/div&gt;

                &lt;div class="field"&gt;
                    &lt;label for="billingAddress-postCode"&gt;Post Code&lt;/label&gt;
                    &lt;input class="required-toggle post-code" type="text" id="billingAddress-postCode" name="billingAddress[postCode]" value=""&gt;
                &lt;/div&gt;
            &lt;/div&gt;

            &lt;div class="field"&gt;
                &lt;label for="billingAddress-countryId"&gt;Country&lt;/label&gt;
                &lt;select class="address-country u-full-width form-control input-sm" id="billingAddress-countryId" name="billingAddress[countryId]"&gt;
                    &lt;option value="77"&gt;United Kingdom&lt;/option&gt;
                &lt;/select&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;div class="continue-button-wrapper"&gt;
            &lt;input class="continue button" type="submit" value="Continue"&gt;
        &lt;/div&gt;

    &lt;/form&gt;
</code></pre>

<plugin-craftcommerce><addresses>
How to make the shipping address and billing address the same?
# How to make the shipping address and billing address the same?

(Asked by: username_0 on 2018-01-03)

I have a checkout page where a user puts in their shipping address. At the bottom is a checkmark which by default sets the shipping address to be the same as the billing address. This however does not work.



  
    Use same address for billing
  


If the checkmark is unchecked the sameAddress value is set to 0, the billing address fields appear and you can type in a different billing address. This does work.
I'm using sameAddress = 1 as advised in the documentation but it doesn't seem to work. Here's the relevant js that toggles the billing address and same address value. Is hiding he billing address fields causing some sort of error?
    $("#sameAddress").change(function (e) {
        $('.billingAddress').toggleClass('hidden');
        if (this.checked) {
            $('.required-toggle').removeAttr('required');
            $('.sameAddressValue').val(1);
        } else{
            $('.required-toggle').attr('required', '');
            $('.sameAddressValue').val(0);
        }
    });

Edit: Adding all the form code


        
        

        {{ getCsrfInput() }}

        Delivery address

        
            
                First Name
                
            

            
                Last Name
                
            
        

        
            Company (optional)
            
        

        
            Email
            
        

        
            Phone
            
        


        
            Address 1
            
        

        
            Address 2
            
        

        
            
                City
                
            

            
                Post Code
                
            
        

        
            Country
            
                United Kingdom
            
        

        {# Use same address button #}
        
        
            Use same address for
        billing
        

        
            Billing address

            
                
                    First Name
                    
                

                
                    Last Name
                    
                
            

            
                Company (optional)
                
            

            
                Email
                
            

            
                Phone
                
            


            
                Address 1
                
            

            
                Address 2
                
            

            
                
                    City
                    
                

                
                    Post Code
                    
                
            

            
                Country
                
                    United Kingdom

**Tags:** plugin-craftcommerce, addresses


---

## 1 answers

### Answer by username_1 on 2018-01-04. Score: 2

[Docs](https://craftcommerce.com/docs/update-cart-addresses#summary)

> As you can see from both examples, the **shipping address** is **always** submitted, and the **billingAddress** can either be also included, or set to the same address as the shipping address with the sameAddress param.

The shippings address is always submitted -> the billing address can be included or not

Your statement:

> At the bottom is a checkmark which by default sets the shipping address to be the same as the billing address. This however does not work.

You set the **shipping address** like **billing address** which is the other way around and won't work unless you change the logic

> **Comments:**
> **username_0**: Thanks Robin. So if I follow you correctly I should swap them and ask for a billing address first and then have a toggle that asks "Use same address for shipping"? Is that what you mean?  
> **username_0**: I've just tried swapping them Robin (asking for the billing first) but the problem persists. Hmmm  
> **username_1**: You said you set the shipping address to the billing address and that's not going to work (like I posted) now in your comment you say "I swap them and ask for the billing address first" which is the same like your first approach. You must check for the shipping address. You NEED the shipping address, the billing address is optional. You can set the billing address to the shipping address  
> **username_0**: Oh I'm sorry Robin I wasn't being clear. I've posted the full code of the form to the post now so you can see. I'm asking for the shipping address first, then electively giving the user the option to put in a different billing address if they want. If the user leaves the "Use same address for billing" box ticked though it doesn't work.  
> **username_1**: Could you please explain that a little bit further? Does the billing address keeps the same as before? Does it become blank? You could check the file `Commerce_CartController.php` line 222 `$result = craft()->commerce_orders->setOrderAddresses($cart, $shippingAddress, $shippingAddress);` and include a `var_dump` if this statement is reached. This stores the shipping address as your billing address. You can check your `$sameAddress` parameter as well if its the correct value  
> **username_0**: Ok, I just got it working. I changed tack, since the hidden Billing Address forms appeared to be causing the problem I moved them to a separate billing.html  and then used ajax to load in billing.html when the "Use same address for billing" was turned off. I appreciate all your effort though, Robin. Helps just to talk a problem through with someone!  
> **username_1**: Ahh no I found the real problem. I did not expect this to happen since its common sense... You named your checkbox and your hidden field equal. That was causing the problem names should be unique in a form if it's not an array  

---

