Loading..
Processing... Please wait...

Product was successfully added to your shopping cart.



Magento 2 make my billing and shipping address the same

Magento 2 checkout sets 'My billing and shipping address are the same' as checked by default.

Magento 2 checked My billing and shipping address are the same Magento 2 checked My billing and shipping address are the same

Often times you want to disable it and make it unchecked by default. I will show you how.

Solution

It seems like a simple html edit but it is not.

We need to modify applyBillingAddress function in vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js around line 231:

applyBillingAddress applyBillingAddress

And comment out this part:

/*                if (shippingAddress &&
                    shippingAddress.canUseForBilling() &&
                    (shippingAddress.isDefaultShipping() || !quote.isVirtual())
                ) { 
                    selectBillingAddress(quote.shippingAddress());
                }   
*/

And we need to modify file vendor/magento/module-checkout/view/frontend/web/js/model/shipping-save-processor/default.js :

vendor/magento/module-checkout/view/frontend/web/js/model/shipping-save-processor/default.js vendor/magento/module-checkout/view/frontend/web/js/model/shipping-save-processor/default.js

And commend out code around line 34:

 /*
                if (!quote.billingAddress()) {
                    selectBillingAddressAction(quote.shippingAddress());
                }   
 */

 

But we can't modify the core javascript files itself (Magento 2 best practices!).

Instead we will create a simple Magento 2 module and will create a file app/code/Vendor/Module/view/frontend/requirejs-config.js with the following 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'
 }
}};

Then copy 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 and comment out in app/code/Vendor/Module/view/frontend/web/js/checkout-data-resolver.js 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());
                }*/
            }

And copy 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 and in app/code/Vendor/Module/view/frontend/web/js/shipping-save-processor/default.js comment out code around line 34:

        'use strict';

        return {
            saveShippingInformation: function () {
                var payload;

                /*if (!quote.billingAddress()) {
                    selectBillingAddressAction(quote.shippingAddress());
                }*/

                payload = { 
                    addressInformation: {
                        shipping_address: quote.shippingAddress(),
                        billing_address: quote.billingAddress(),

 

After that delete pub/static/frontend folder regenerate your static content:

php bin/magento setup:static-content:deploy

Clear magento cache and you should be all set.

 

  

Need help with a Magento site? Hire me!

 

Like the article? Share:

 

Other articles you might be interested in:

  1. Upgrade Magento 1.9.1 php issue
  2. Fixing infinite redirect loop when ssl enabled in magento admin area
  3. Magento 1.9.3.1 on HHVM beats PHP7
  4. Magento 1.7.0.0-alpha1 Preview Release - old notification.rss bug!
  5. How to increase speed of magento website

  

If you find this post interesting do not hesitate to sign up for our newsletter and join the 865 people who receive Magento news, tips and tricks regularly.

Thank You!

 

 

5 thoughts on “Magento 2 make my billing and shipping address the same”
  • Cat

    Hey,
    Thanks for the solution, but just a heads up to others to make sure you test this thoroughly - especially if you're using PayPal express checkout alongside credit/debit card.
    We found that this broke PayPal checkout as there was no address being set as it uses the billing address from the credit card area (even though the customer is never shown this on the Paypal route)

    Thanks!

  • Konstantin Gerasimov

    @Ale why do you think so?

  • Ale

    Magento is EVIL

  • Konstantin Gerasimov

    @Michael - I don't quite understand what you are after

    you can send me a request at www.goivvy.com/contacts and we can take it from there

  • Michael

    Hi

    Is it safe to assume that you'd apply something similar to Gift Messages ... is there a particular file(s) I should be looking at?

    Thanks

    - michael