{"id":1623,"date":"2021-03-04T21:09:11","date_gmt":"2021-03-04T21:09:11","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-customer-by-email-in-magento-2\/"},"modified":"2025-05-21T17:07:46","modified_gmt":"2025-05-21T11:37:46","slug":"get-customer-by-email-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-customer-by-email-in-magento-2\/","title":{"rendered":"How to Get Customer by Email in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Customer data management is something that an admin cannot go away with while administering a Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Anything from marketing to customer experience, shipping, etc. requires the admin to get customer data for working efficiently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, you want to implement validation based on customer groups, run an age-group-focused marketing campaign, or offer after-sales service to customers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All these things require to get customer data in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One way to achieve this is to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/get-all-orders-of-customer-by-email-id-in-magento-2\/\">get all orders of a customer by email ID<\/a>, which provides a comprehensive view of their purchasing history and enables targeted marketing efforts. This data can be accessed through Magento 2\u2019s customer management system, allowing for personalized and effective customer engagement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usually, one can get a customer by ID in Magento 2. However, if you do not have a customer ID, I will show how to&nbsp;get customer by Email in Magento 2!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can get customer id, first name, last name, and other customer-specific data by just passing the customer email id using the below code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Customer by Email in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code in helper file&nbsp;<strong>Data.php<\/strong>&nbsp;at&nbsp;<strong>Vendor\/Extension\/Helper<\/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 Vendore\\Extension\\Helper;\n\nuse Magento\\Customer\\Model\\CustomerFactory;\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\Store\\Model\\StoreManagerInterface;\n\nclass Data extends AbstractHelper\n{\n    protected $customer;\n    protected $storemanager;\n\n    public function __construct(\n        Context $context,\n        CustomerFactory $customer,\n        StoreManagerInterface $storemanager\n    )\n    {\n        $this->customer = $customer;\n        $this->storemanager = $storemanager;\n        parent::__construct($context);\n    }\n\n    public function getCustomerByEmail($email)\n    {\n\n        $websiteID = $this->storemanager->getStore()->getWebsiteId();\n        $customer = $this->customer->create()->setWebsiteId($websiteID)->loadByEmail($email);\n\n        return $customer;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s all!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I would be happy to help.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Customer data management is something that an admin cannot go away with while administering a Magento 2 store. Anything from marketing to customer experience, shipping,&#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-1623","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1623","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=1623"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1623\/revisions"}],"predecessor-version":[{"id":13865,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1623\/revisions\/13865"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}