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

Product was successfully added to your shopping cart.



Magento 2 set unchecked my billing and shipping address are the same by default on checkout

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.

 

 

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

Thank You!

 

 

2 thoughts on “Magento 2 set unchecked my billing and shipping address are the same by default on checkout”

  • 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