{"id":838,"date":"2020-03-02T09:32:03","date_gmt":"2020-03-02T09:32:03","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/03\/02\/magento-2-get-customer-address-data-by-address-id\/"},"modified":"2025-05-22T14:51:53","modified_gmt":"2025-05-22T09:21:53","slug":"magento-2-get-customer-address-data-by-address-id","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-get-customer-address-data-by-address-id\/","title":{"rendered":"How To Get Customer Address Data By Address ID In Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The post gives the solution to&nbsp;get customer address data by address ID in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Magento 2 store owners may sometimes employ techniques such as restricting the shipping of fragile or heavy items in certain areas to optimize the profit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, managing the shipping process can be easy with organizing the customer addresses, including the ability to add and manage&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/configure-multiple-shipping-addresses-in-magento-2\/\">multiple shipping addresses<\/a>. By allowing customers to save multiple shipping addresses, it becomes easier for them to choose the correct address during the checkout process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, to implement such a system needs to get customer address data. The below code is an easy programmatic way to get customer address information using address ID in Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Customer address data is got by Address ID using&nbsp;<strong>AddressRepositoryInterface<\/strong>&nbsp;interface.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Customer Address Data by Address ID in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create&nbsp;<em><strong>GetCustomerAddress.php<\/strong><\/em>&nbsp;Class in&nbsp;<strong>app\/code\/Vendor\/Extension\/Model<\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n \nnamespace VendorExtensionModel;\n \nuse MagentoCustomerApiAddressRepositoryInterface;\n \nclass GetCustomerAddress\n{\n    private $addressRepository;\n \n    public function __construct(\n        AddressRepositoryInterface $addressRepository\n    )\n    {\n        $this->addressRepository = $addressRepository;\n    }\n \n    public function getAddressDataById($addressId)\n    {\n        try {\n            $addressData = $this->addressRepository->getById($addressId);\n        } catch (Exception $exception) {\n            throw new Exception($exception->getMessage());\n        };\n        return $addressData;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now you can access getAddressData($addressId) function as per your requirement by extending GetCustomerAddress class<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s all for customer address data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please share the solution with the Magento community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The post gives the solution to&nbsp;get customer address data by address ID in Magento 2. The Magento 2 store owners may sometimes employ techniques such&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-838","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=838"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/838\/revisions"}],"predecessor-version":[{"id":15056,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/838\/revisions\/15056"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}