{"id":1600,"date":"2019-10-18T06:42:04","date_gmt":"2019-10-18T06:42:04","guid":{"rendered":"https:\/\/www.cynoinfotech.com\/?p=1600"},"modified":"2026-04-16T13:32:12","modified_gmt":"2026-04-16T13:32:12","slug":"get-customer-addresses-by-customer-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/","title":{"rendered":"Get Customer Addresses by Customer ID in Magento 2"},"content":{"rendered":"<p>For converting guest checkout to registered customers you\u2019d 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.<\/p>\n<p><strong>you can get customer addresses by ID in Magento 2 store<\/strong><\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\u00a0\r\n\r\nnamespace [Vendor]\\[Module]\\Helper;\r\n\r\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\r\nuse Magento\\Framework\\App\\Helper\\Context;\r\nuse Magento\\Store\\Model\\StoreManagerInterface;\r\nuse Magento\\Customer\\Model\\CustomerFactory;\r\n\r\nclass Data extends AbstractHelper\r\n{\r\n\u00a0 \u00a0 protected $_storeManager;\r\n\u00a0 \u00a0 protected $_customerFactory;\r\n\r\n\u00a0 \u00a0 public function __construct(\r\n\u00a0 \u00a0 \u00a0 \u00a0 Context $context,\r\n\u00a0 \u00a0 \u00a0 \u00a0 StoreManagerInterface $storeManager,\r\n\u00a0 \u00a0 \u00a0 \u00a0 CustomerFactory $customerFactory\r\n\u00a0 \u00a0 ) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 $this-&gt;_storeManager = $storeManager;\r\n\u00a0 \u00a0 \u00a0 \u00a0 $this-&gt;_customerFactory = $customerFactory;\r\n\u00a0 \u00a0 \u00a0 \u00a0 parent::__construct($context);\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 public function getCustomerAddressById($customerId)\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 $customer = $this-&gt;_customerFactory-&gt;create();\r\n\u00a0 \u00a0 \u00a0 \u00a0 $websiteId = $this-&gt;_storeManager-&gt;getStore()-&gt;getWebsiteId();\r\n\u00a0 \u00a0 \u00a0 \u00a0 $customer-&gt;setWebsiteId($websiteId);\r\n\u00a0 \u00a0 \u00a0 \u00a0 $customerModel = $customer-&gt;load($customerId);\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 $customerAddressData = [];\r\n\u00a0 \u00a0 \u00a0 \u00a0 $customerAddress = [];\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 if ($customerModel-&gt;getAddresses() != null)\r\n\u00a0 \u00a0 \u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 foreach ($customerModel-&gt;getAddresses() as $address) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $customerAddress[] = $address-&gt;toArray();\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 if ($customerAddress != null)\r\n\u00a0 \u00a0 \u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 foreach ($customerAddress as $customerAddres)\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $street = $customerAddres['street'];\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $city = $customerAddres['city'];\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $region = $customerAddres['region'];\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $country = $customerAddres['country_id'];\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $postcode = $customerAddres['postcode'];\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 $customerAddressData[] = $customerAddres-&gt;toArray();\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 return $customerAddressData;\r\n\u00a0 \u00a0 }\r\n}\r\n<\/pre>\n<p>Note: Using [Vendor]\\[Module]\\Helper class\u2019s object you can call method getCustomerAddressById() to get Address Data<br \/>\nFor example : $address = $this-&gt;myHelper-&gt;getCustomerAddressById(Id);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For converting guest checkout to registered customers you\u2019d 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. you can get customer addresses by ID in Magento 2 store &lt;?php\u00a0 namespace [Vendor]\\[Module]\\Helper; use Magento\\Framework\\App\\Helper\\AbstractHelper; use Magento\\Framework\\App\\Helper\\Context; use [&hellip;]<\/p>\n","protected":false},"author":670,"featured_media":1605,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[227],"class_list":["post-1600","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento-blog","tag-magento-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Get Customer Addresses by Customer ID in Magento 2 - cynoinfotech<\/title>\n<meta name=\"description\" content=\"For converting guest checkout to registered customers you\u2019d need the customer address. But what if the already signed up customer uses guest checkout!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/\"},\"author\":{\"name\":\"Arjun Makadiya\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/person\\\/f1be8186602d3ebf417cf58baf125f24\"},\"headline\":\"Get Customer Addresses by Customer ID in Magento 2\",\"datePublished\":\"2019-10-18T06:42:04+00:00\",\"dateModified\":\"2026-04-16T13:32:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/\"},\"wordCount\":81,\"publisher\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/customer-address-by-id.jpg\",\"keywords\":[\"Magento Development\"],\"articleSection\":[\"Magento blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/\",\"name\":\"Get Customer Addresses by Customer ID in Magento 2 - cynoinfotech\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/customer-address-by-id.jpg\",\"datePublished\":\"2019-10-18T06:42:04+00:00\",\"dateModified\":\"2026-04-16T13:32:12+00:00\",\"description\":\"For converting guest checkout to registered customers you\u2019d need the customer address. But what if the already signed up customer uses guest checkout!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/customer-address-by-id.jpg\",\"contentUrl\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/10\\\/customer-address-by-id.jpg\",\"width\":895,\"height\":450},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/get-customer-addresses-by-customer-id-in-magento-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Customer Addresses by Customer ID in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\",\"name\":\"cynoinfotech\",\"description\":\"web design &amp; development\",\"publisher\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\",\"name\":\"Cynoinfotech\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.cynoinfotech.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/final-logo-ci.png\",\"contentUrl\":\"https:\\\/\\\/www.cynoinfotech.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/final-logo-ci.png\",\"width\":240,\"height\":70,\"caption\":\"Cynoinfotech\"},\"image\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/cynoinfotech\\\/\",\"https:\\\/\\\/x.com\\\/cynoinfotech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/person\\\/f1be8186602d3ebf417cf58baf125f24\",\"name\":\"Arjun Makadiya\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"caption\":\"Arjun Makadiya\"},\"description\":\"Arjun Makadiya is a Junior Magento Developer at Cynoifotech. He is passionate about technology. Apart from work he likes to play cricket.\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/author\\\/arjun-makadiya\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Customer Addresses by Customer ID in Magento 2 - cynoinfotech","description":"For converting guest checkout to registered customers you\u2019d need the customer address. But what if the already signed up customer uses guest checkout!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/"},"author":{"name":"Arjun Makadiya","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24"},"headline":"Get Customer Addresses by Customer ID in Magento 2","datePublished":"2019-10-18T06:42:04+00:00","dateModified":"2026-04-16T13:32:12+00:00","mainEntityOfPage":{"@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/"},"wordCount":81,"publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"image":{"@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/cynoinfotech.com\/blog\/wp-content\/uploads\/2019\/10\/customer-address-by-id.jpg","keywords":["Magento Development"],"articleSection":["Magento blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/","url":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/","name":"Get Customer Addresses by Customer ID in Magento 2 - cynoinfotech","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/cynoinfotech.com\/blog\/wp-content\/uploads\/2019\/10\/customer-address-by-id.jpg","datePublished":"2019-10-18T06:42:04+00:00","dateModified":"2026-04-16T13:32:12+00:00","description":"For converting guest checkout to registered customers you\u2019d need the customer address. But what if the already signed up customer uses guest checkout!","breadcrumb":{"@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/#primaryimage","url":"https:\/\/cynoinfotech.com\/blog\/wp-content\/uploads\/2019\/10\/customer-address-by-id.jpg","contentUrl":"https:\/\/cynoinfotech.com\/blog\/wp-content\/uploads\/2019\/10\/customer-address-by-id.jpg","width":895,"height":450},{"@type":"BreadcrumbList","@id":"https:\/\/cynoinfotech.com\/blog\/get-customer-addresses-by-customer-id-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cynoinfotech.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Get Customer Addresses by Customer ID in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/cynoinfotech.com\/blog\/#website","url":"https:\/\/cynoinfotech.com\/blog\/","name":"cynoinfotech","description":"web design &amp; development","publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cynoinfotech.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cynoinfotech.com\/blog\/#organization","name":"Cynoinfotech","url":"https:\/\/cynoinfotech.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png","contentUrl":"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png","width":240,"height":70,"caption":"Cynoinfotech"},"image":{"@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cynoinfotech\/","https:\/\/x.com\/cynoinfotech"]},{"@type":"Person","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24","name":"Arjun Makadiya","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","caption":"Arjun Makadiya"},"description":"Arjun Makadiya is a Junior Magento Developer at Cynoifotech. He is passionate about technology. Apart from work he likes to play cricket.","url":"https:\/\/cynoinfotech.com\/blog\/author\/arjun-makadiya\/"}]}},"_links":{"self":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/1600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/users\/670"}],"replies":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=1600"}],"version-history":[{"count":5,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/1600\/revisions"}],"predecessor-version":[{"id":3181,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/1600\/revisions\/3181"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/media\/1605"}],"wp:attachment":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=1600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=1600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=1600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}