How To

How to set Address Limitation for Logged In Customer on Checkout page of Magento 2

Ecommerce checkout is a crucial part of any Magento store. Because keeping your checkout process smooth and interactive helps you to boost your store conversion rate drastically. While having a complicated checkout process can increase your store cart abandon rate. If you see the whole checkout process is divided into many steps where your customer has to add their shipping address first then select the shipping method and payment option to complete an order.
By default, your store customer can add several addresses inside your Magento 2 store. Also, they can easily manage all the addresses from their My Account section. But having multiple addresses makes a cumbersome task for your customers to select a particular address even if they don’t use all the addresses too frequently. Instead, we can display only last used 4 or 5 addresses in checkout options. Also, hiding adds address option while checkout reduces your conversation time. But there is no such option in Magento 2 backend so the only way it overrides your default theme checkout page.
To do the same. First copy the following file in your local theme.
Vendor\magento\module-checkout\view\frontend\web\js\view\shipping-address\list.js
Now find and modify the following function.
initChildren: function () {

 if(addressList().length > 0){
        this.createRendererComponent(addressList()[0],this); /* It always set the first shipping address. Change the logic as per your requirement */ }
 else{
     _.each(addressList(), this.createRendererComponent, this);
 }
 return this;
},

Now, to hide New Address button and copy the html template from…
Vendor\magento\module-checkout\view\frontend\web\template\shipping.html
To your local theme and comment the below code

         
     

That’s it. You are free to manipulate this code according to your need of adjusting the number of addresses that you want to display in frontend checkout. Also, install Custom Checkout Fields which helps the store admin customize the checkout page by adding extra fields.
Lastly, if you found this blog helpful, don’t forget to share it with your colleagues and Magento Friends and Let us know if you are facing any issue while implementing this code.
Happy Coding!

Click to rate this post!
[Total: 7 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

View Comments

  • How can i filter the record based on any column from customer_address_entity table in magento 2

    • The collection filter you can do from where that collection create, this is just view files of that one

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

3 days ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

4 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

5 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

7 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

1 week ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago