3

I am using Magento 2.0.7 and my default billing and shipping address are different in My account Address section.

When I am going on checkout page my default shipping address selected by default and I move on payment section but on payment section My shipping address by default set as billing address.

I already mention default billing address then how we get that address selected by default ?

2
  • Hi did you get a solution for this? Mar 16, 2017 at 4:54
  • Hi Ashish, I face some different kind of problem but If you can write the solution of this than it's may be its help full. Sep 12, 2017 at 6:55

2 Answers 2

5

You could do the following:

  • overwrite a default js file checkout-data-resolver.js
  • add extra lines to the applyBillingAddress function to check if default billing address exists and if true to use it

step 1. Overwritting a default magento checkout-data-resolver.js

  • 1.1 Create your module. YourCompany\Checkout

  • 1.2 Add file \app\code\YourCompany\Checkout\view\frontend\requirejs-config.js

with following content

var config = {
map: {
    '*': {
        'Magento_Checkout/js/model/checkout-data-resolver': 
    'YourCompany_Checkout/js/model/checkout-data-resolver'        
    }
}

};
  • 1.3 Copy magento file \vendor\magento\module-checkout\view\frontend\web\js\model\checkout-data-resolver.js to the destination \app\code\YourCompany\Checkout\view\frontend\web\js\model\checkout-data-resolver.js

step 2. Modify applyBillingAddress function

2.1 in new checkout-data-resolver.js file find applyBillingAddress. Insert following cod after var shippingAddress; and before if (quote.billingAddress())

....
var isBillingAddressInitialized;
isBillingAddressInitialized = addressList.some(function (addressFromList) {
  if (addressFromList.isDefaultBilling()) {
     selectBillingAddress(addressFromList);
              return true;
    }

  return false;
 });

if(isBillingAddressInitialized){
                 return;
             }  
....

This code actually goes through customer addresses and checks if any of them has defaultBilling set to true. If such an address exists it will be used as the billing address. If not the script will fall back to the default magento behavior

3
  • I'm running into a similar issue, but only when I add a new address in the shipping step prior to going to the payment step, it ends up taking the new shipping address and automatically changing the default billing address to the new shipping address. Any idea what could cause that? I tried this fix, however the issue persists.
    – ne0nlight
    Oct 10, 2018 at 19:40
  • Can you post same answer for shipping address , its gets unselected after adding new billing address. Apr 6, 2020 at 8:17
  • I'm getting select billing address but its only show pin code or country name Oct 28, 2020 at 11:57
-1

I got solution of this problem. please check your theme override file:

/app/design/frontend/Vendor/your-theme/Magento_Checkout/web/js/view/shipping.js

in this file checkout your custom code on line no 114 or may be change of this line your file. So, checkout this function

initialize: function ()

Inside this function check following code

 registry.async('checkoutProvider')(function (checkoutProvider) {
       //////////
          Your Code 
      /////////    
 });

from this jQuery remove your custom code or update with new code.

hope it will work for you. In my case it is working for me after update this function.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.