Feel free to share the solution with Magento Community via social media.
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 get customer by Email in Magento 2!
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.
Customer data management is something that an admin cannot go away with while administering a Magento 2 store.
Use the below code in helper file Data.php at Vendor/Extension/Helper
All these things require to get customer data in Magento 2.
Method to Get Customer by Email in Magento 2
Something went wrong.
class Data extends AbstractHelper
public function __construct(
$this->customer = $customer;
$this->storemanager = $storemanager;
public function getCustomerByEmail($email)
$websiteID = $this->storemanager->getStore()->getWebsiteId();
$customer = $this->customer->create()->setWebsiteId($websiteID)->loadByEmail($email);
Never miss Magento tips, tricks, tutorials, and news.
Anything from marketing to customer experience, shipping, etc. requires the admin to get customer data for working efficiently.
I would be happy to help.
Thank you for subscribing.
Get Weekly Updates
If you are stuck anywhere by using this solution, do mention them in the Comment section below.
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.