How to Get Customer Addresses by Customer ID in Magento 2

If you want to implement any features in the Magento 2 store based on the customer address, this post is for you.

For example, while implementing guest checkout and then automatically converting them to registered customers. For that, you’d need the customer address. But what if the already signed up customer uses guest checkout! The duplicate addresses are saved and it will mess up the address database.

To avoid that, you can get customer addresses by customer ID in Magento 2 store and then check for duplicate values.

The below solution helps you collect all customer addresses using customer ID:

Method to Get Customer Addresses by Customer ID in Magento 2:

Note: Using [Vendor]\[Module]\Helper class’s  object you can call method getCustomerAddress(id) to get Address Data

For example : $address = $this->myHelper->getCustomerAddress(5);

That’s it.

Any doubts in the implementation can be mentioned in the Comments section below and I’d be glad to help you out.

Do share the solution with fellow developers via social media.

Thanks.

5
(based on 6 Reviews)
How to Get Customer Addresses by Customer ID in Magento 2

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply

Your email address will not be published. Required fields are marked *