{"id":2644,"date":"2021-01-22T09:45:53","date_gmt":"2021-01-22T09:45:53","guid":{"rendered":"https:\/\/www.cynoinfotech.com\/?p=2644"},"modified":"2026-04-16T13:32:11","modified_gmt":"2026-04-16T13:32:11","slug":"how-to-get-customer-data-by-customer-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/","title":{"rendered":"How to get customer data by customer id in Magento 2?"},"content":{"rendered":"<p>How can we get the customer data from id, not from customer session in Magento 2?<\/p>\n<p><strong>you can get customer addresses by ID in Magento 2 store<\/strong><\/p>\n<p>[php]<br \/>\n&lt;?php<\/p>\n<p>namespace Vender\\Module\\Block <\/p>\n<p>class Customer extends \\Magento\\Framework\\View\\Element\\Template<br \/>\n{<br \/>\n    protected $customerRepository;<\/p>\n<p>    public function __construct(<br \/>\n        \\Magento\\Customer\\Api\\CustomerRepositoryInterfaceFactory $customerRepositoryFactory<br \/>\n\t) {<br \/>\n        $this-&gt;customerRepository = $customerRepositoryFactory-&gt;create();<br \/>\n\t}<\/p>\n<p>    public function LoadCustomerById($customerId) {<br \/>\n         $customer = $this-&gt;customerRepository-&gt;getById($customerId);<br \/>\n         return $customer;<br \/>\n    }<br \/>\n}<br \/>\n?&gt;<br \/>\n[\/php]<\/p>\n<p>You can get customer data by just using the customer id using the below code.<\/p>\n<p>[php]<br \/>\n&lt;?php<br \/>\n$customerId = 1; \/\/pass dynamic customer id<br \/>\n$customer = $block-&gt;LoadCustomerById($customerId);<br \/>\necho $customer-&gt;getFirstname();  \/\/ result customer first name<br \/>\necho $customer-&gt;getEmail(); \/\/ result as customer email<br \/>\necho $customer-&gt;getLastname(); \/\/ customerr lastname<br \/>\n?&gt;<br \/>\n[\/php]<\/p>\n<p>You can get customer data by customer id using Object Manager.<\/p>\n<p>[php]<br \/>\n&lt;?php<br \/>\n$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();<br \/>\n$customerId = 1; \/\/pass dynamic customer id<br \/>\n$customer = $objectManager-&gt;create(&#8216;Magento\\Customer\\Model\\Customer&#8217;)-&gt;load($customerId);<br \/>\n$email = $customer-&gt;getEmail();<br \/>\n?&gt;<br \/>\n[\/php]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How can we get the customer data from id, not from customer session in Magento 2? you can get customer addresses by ID in Magento 2 store [php] &lt;?php namespace Vender\\Module\\Block class Customer extends \\Magento\\Framework\\View\\Element\\Template { protected $customerRepository; public function __construct( \\Magento\\Customer\\Api\\CustomerRepositoryInterfaceFactory $customerRepositoryFactory ) { $this-&gt;customerRepository = $customerRepositoryFactory-&gt;create(); } public function LoadCustomerById($customerId) { $customer = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2644","post","type-post","status-publish","format-standard","hentry","category-magento-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to get customer data by customer id in Magento 2? - cynoinfotech<\/title>\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\/how-to-get-customer-data-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\\\/how-to-get-customer-data-by-customer-id-in-magento-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-customer-id-in-magento-2\\\/\"},\"author\":{\"name\":\"Cynoinfotech\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/person\\\/171ca984a087c48eb62a76a6c556b5cb\"},\"headline\":\"How to get customer data by customer id in Magento 2?\",\"datePublished\":\"2021-01-22T09:45:53+00:00\",\"dateModified\":\"2026-04-16T13:32:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-customer-id-in-magento-2\\\/\"},\"wordCount\":176,\"publisher\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\"},\"articleSection\":[\"Magento blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-customer-id-in-magento-2\\\/\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-customer-id-in-magento-2\\\/\",\"name\":\"How to get customer data by customer id in Magento 2? - cynoinfotech\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#website\"},\"datePublished\":\"2021-01-22T09:45:53+00:00\",\"dateModified\":\"2026-04-16T13:32:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-customer-id-in-magento-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-customer-id-in-magento-2\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/how-to-get-customer-data-by-customer-id-in-magento-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get customer data 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\\\/171ca984a087c48eb62a76a6c556b5cb\",\"name\":\"Cynoinfotech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7ed63814d1ba50e7872feed454a54981ae63a5c8d6c0ccf07b4258bef9c78ea2?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7ed63814d1ba50e7872feed454a54981ae63a5c8d6c0ccf07b4258bef9c78ea2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7ed63814d1ba50e7872feed454a54981ae63a5c8d6c0ccf07b4258bef9c78ea2?s=96&d=mm&r=g\",\"caption\":\"Cynoinfotech\"},\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/author\\\/madhaviweb\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get customer data by customer id in Magento 2? - cynoinfotech","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\/how-to-get-customer-data-by-customer-id-in-magento-2\/","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/"},"author":{"name":"Cynoinfotech","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/171ca984a087c48eb62a76a6c556b5cb"},"headline":"How to get customer data by customer id in Magento 2?","datePublished":"2021-01-22T09:45:53+00:00","dateModified":"2026-04-16T13:32:11+00:00","mainEntityOfPage":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/"},"wordCount":176,"publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"articleSection":["Magento blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/","url":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/","name":"How to get customer data by customer id in Magento 2? - cynoinfotech","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/#website"},"datePublished":"2021-01-22T09:45:53+00:00","dateModified":"2026-04-16T13:32:11+00:00","breadcrumb":{"@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cynoinfotech.com\/blog\/how-to-get-customer-data-by-customer-id-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cynoinfotech.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to get customer data 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\/171ca984a087c48eb62a76a6c556b5cb","name":"Cynoinfotech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/7ed63814d1ba50e7872feed454a54981ae63a5c8d6c0ccf07b4258bef9c78ea2?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/7ed63814d1ba50e7872feed454a54981ae63a5c8d6c0ccf07b4258bef9c78ea2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7ed63814d1ba50e7872feed454a54981ae63a5c8d6c0ccf07b4258bef9c78ea2?s=96&d=mm&r=g","caption":"Cynoinfotech"},"url":"https:\/\/cynoinfotech.com\/blog\/author\/madhaviweb\/"}]}},"_links":{"self":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/2644","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=2644"}],"version-history":[{"count":24,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/2644\/revisions"}],"predecessor-version":[{"id":2682,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/2644\/revisions\/2682"}],"wp:attachment":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=2644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=2644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=2644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}