Magento – Magento 2 Set “Billing Same as Shipping” default to unchecked

billingcheckoutmagento-2.1shipping

In the Magento 2 checkout process, the second screen displays your shipping address again with a checkbox that is checked by default.

How do I make that unchecked by default, so the user can enter their billing info?

Best Answer

Disclaimer: I am an author of an article at the end of this answer. The following solution tested on M2.1.4

Magento best practices way.

  1. Create a simple Magento 2 extension.
  2. Create a file app/code/Vendor/Module/view/frontend/requirejs-config.js with the content:

    var config = {
     map: {
     '*': {
       'Magento_Checkout/js/model/checkout-data-resolver': 'Vendor_Module/js/checkout-data-resolver',
       'Magento_Checkout/js/model/shipping-save-processor/default': 'Vendor_Module/js/shipping-save-processor/default'
      }
    }};
    
  3. Copy file vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js to app/code/Vendor/Module/view/frontend/web/js/checkout-data-resolver.js.
  4. Edit file app/code/Vendor/Module/view/frontend/web/js/checkout-data-resolver.js and comment out code around line 231:

        applyBillingAddress: function () {
            var shippingAddress;
    
            if (quote.billingAddress()) {
                selectBillingAddress(quote.billingAddress());
    
                return;
            }
            shippingAddress = quote.shippingAddress();
    
            /*if (shippingAddress &&
                shippingAddress.canUseForBilling() &&
                (shippingAddress.isDefaultShipping() || !quote.isVirtual())
            ) {
                selectBillingAddress(quote.shippingAddress());
            }*/
        }
    };
    
  5. Copy file vendor/magento/module-checkout/view/frontend/web/js/model/shipping-save-processor/default.js to app/code/Vendor/Module/view/frontend/web/js/shipping-save-processor/default.js.

  6. In app/code/Vendor/Module/view/frontend/web/js/shipping-save-processor/default.js comment out code around line 34:

    saveShippingInformation: function () {
    var payload;
    
    /*if (!quote.billingAddress()) {
        selectBillingAddressAction(quote.shippingAddress());
    }*/
    
    payload = {
    
  7. Delete folder pub/static/frontend:

     rm -rf pub/static/frontend
    
  8. Regenerate static content:

     php bin/magento setup:static-content:deploy
    
  9. Clear magento cache and you are all set.

Dirty way

Instead of steps 1 through 6 simply edit the file vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js and comment out code around line 231 as in step 4 and edit the file vendor/magento/module-checkout/view/frontend/web/js/model/shipping-save-processor/default.js and comment code code around line 34 as in step 6.

Repeat steps 7,8,9.

Originally published as https://www.goivvy.com/blog/magento-2-set-billing-shipping-address-unchecked-default-checkout