Magento – Magento 2 : Uncheck My billing and shipping address are the same checkbox in checkout payment page based on shipping method

magento-2.1magento2

I am working on magento 2.1.3.
I want to uncheck My billing and shipping address are the same checkbox in checkout payment page based on shipping method.

If shipping method is Store Pickup i want to uncheck checkbox by default.

Best Answer

Disclaimer: I am an author of an article at the end of this answer.

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