Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T13:04:05.083Z
Answers.Text: 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?
Answers.UserDisplayName: patrick.altair
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T13:15:06.000Z
Answers.Text: I've just tried swapping them Robin (asking for the billing first) but the problem persists. Hmmm
Answers.UserDisplayName: patrick.altair
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T14:03:45.690Z
Answers.Text: 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
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T16:14:58.927Z
Answers.Text: 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.
Answers.UserDisplayName: patrick.altair
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T16:27:21.853Z
Answers.Text: 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
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T17:10:31.500Z
Answers.Text: 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!
Answers.UserDisplayName: patrick.altair
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T17:14:40.053Z
Answers.Text: 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
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T07:40:25.497Z
Answers.LastActivityDate: 2018-01-04T07:40:25.497Z
Answers.UserDisplayName: Robin Schambach
Body: <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>
  
Tags: <plugin-craftcommerce><addresses>
Title: How to make the shipping address and billing address the same?
ThreadText: # 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.
  
  ```
  <input type="hidden" name="sameAddress" class="sameAddressValue" value="1">
  
  <div class="use-same-address">
    <label for="sameAddress"><input id="sameAddress" name="sameAddress" type="checkbox" checked="checked"/>
      <span class="label-body">Use same address for billing</span>
    </label>
  </div>
  
  ```
  
  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
  
  ```
  <form method="post">
  
          <input type="hidden" name="action" value="commerce/cart/updateCart">
          <input type="hidden" name="redirect" value="shop/checkout/payment"/>
  
          {{ getCsrfInput() }}
  
          <h3>Delivery address</h3>
  
          <div class="half-width">
              <div class="field">
                  <label for="shippingAddress-firstName">First Name</label>
                  <input type="text" id="shippingAddress-firstName" name="shippingAddress[firstName]" pattern=".{2,}" required value="">
              </div>
  
              <div class="field">
                  <label for="shippingAddress-lastName">Last Name</label>
                  <input type="text" id="shippingAddress-lastName" name="shippingAddress[lastName]" required value="">
              </div>
          </div>
  
          <div class="field  clear">
              <label for="shippingAddress-businessName">Company (optional)</label>
              <input type="text" id="shippingAddress-businessName" name="shippingAddress[businessName]" value="">
          </div>
  
          <div class="field  clear">
              <label for="">Email</label>
              <input type="text" value="{{ cart.email }}" name="email" required placeholder="example@site.com"/>
          </div>
  
          <div class="field  clear">
              <label for="shippingAddress-phone">Phone</label>
              <input type="text" id="shippingAddress-phone" class="u-full-width" placeholder="020 7946 0123" name="shippingAddress[phone]" required value="">
          </div>
  
          <div class="field clear">
              <label for="shippingAddress-address1">Address 1</label>
              <input type="text" id="shippingAddress-address1" name="shippingAddress[address1]" required value="">
          </div>
  
          <div class="field clear">
              <label for="shippingAddress-address2">Address 2</label>
              <input type="text" id="shippingAddress-address2" name="shippingAddress[address2]" value="">
          </div>
  
          <div class="half-width">
              <div class="field">
                  <label for="shippingAddress-city">City</label>
                  <input type="text" id="shippingAddress-city" name="shippingAddress[city]" required value="">
              </div>
  
              <div class="field">
                  <label for="shippingAddress-postCode">Post Code</label>
                  <input type="text" id="shippingAddress-postCode" name="shippingAddress[postCode]" maxlength="8" required value="">
              </div>
          </div>
  
          <div class="field clear">
              <label for="shippingAddress-countryId">Country</label>
              <select class="address-country u-full-width form-control input-sm" id="shippingAddress-countryId" name="shippingAddress[countryId]">
                  <option value="77">United Kingdom</option>
              </select>
          </div>
  
          {# Use same address button #}
          <input type="hidden" name="sameAddress" class="sameAddressValue" value="1">
          <div class="use-same-address">
              <label for="sameAddress"><input id="sameAddress" name="sameAddress" type="checkbox" checked="checked"/><span class="label-body">Use same address for
          billing</span></label>
          </div>
  
          <div class="billingAddress hidden">
              <h3>Billing address</h3>
  
              <div class="half-width">
                  <div class="field">
                      <label for="billingAddress-firstName">First Name</label>
                      <input class="required-toggle" type="text" id="billingAddress-firstName" name="billingAddress[firstName]" value="">
                  </div>
  
                  <div class="field">
                      <label for="billingAddress-lastName">Last Name</label>
                      <input class="required-toggle" type="text" id="billingAddress-lastName" name="billingAddress[lastName]" value="">
                  </div>
              </div>
  
              <div class="field  clear">
                  <label for="billingAddress-businessName">Company (optional)</label>
                  <input type="text" id="billingAddress-businessName" name="billingAddress[businessName]" value="">
              </div>
  
              <div class="field  clear">
                  <label for="">Email</label>
                  <input class="required-toggle" type="text" value="{{ cart.email }}" name="email" placeholder="email@site.com"/>
              </div>
  
              <div class="field  clear">
                  <label for="billingAddress-phone">Phone</label>
                  <input class="required-toggle" type="text" id="billingAddress-phone" class="u-full-width" name="billingAddress[phone]" value="">
              </div>
  
              <div class="field clear">
                  <label for="billingAddress-address1">Address 1</label>
                  <input class="required-toggle" type="text" id="billingAddress-address1" name="billingAddress[address1]" value="">
              </div>
  
              <div class="field clear">
                  <label for="billingAddress-address2">Address 2</label>
                  <input type="text" id="billingAddress-address2" name="billingAddress[address2]" value="">
              </div>
  
              <div class="half-width">
                  <div class="field">
                      <label for="billingAddress-city">City</label>
                      <input class="required-toggle" type="text" id="billingAddress-city" name="billingAddress[city]" value="">
                  </div>
  
                  <div class="field">
                      <label for="billingAddress-postCode">Post Code</label>
                      <input class="required-toggle post-code" type="text" id="billingAddress-postCode" name="billingAddress[postCode]" value="">
                  </div>
              </div>
  
              <div class="field">
                  <label for="billingAddress-countryId">Country</label>
                  <select class="address-country u-full-width form-control input-sm" id="billingAddress-countryId" name="billingAddress[countryId]">
                      <option value="77">United Kingdom</option>
                  </select>
              </div>
          </div>
  
          <div class="continue-button-wrapper">
              <input class="continue button" type="submit" value="Continue">
          </div>
  
      </form>
  
  ```
  
  **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 username_1. 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 username_1 (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 username_1 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, username_1. 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  
  
  ---
  
  