You can get customer information by just passing customer email using below code snippet, Create Block file,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?php namespace Rbj\Customer\Block; class Customer extends \Magento\Framework\View\Element\Template { public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, array $data = [] ) { $this->customerRepository = $customerRepository; parent::__construct($context, $data); } /* * $email string * $websiteId int */ public function getCustomerByEmail($email,$websiteId = null) { return $this->customerRepository->get($email,$websiteId); } |
Call getCustomerByEmail() function in template file,
1 2 3 4 5 6 | $customerEmail = 'roni_cost@example.com'; $websiteId = 1; // pass website id $customer = $block->getCustomerByEmail($customerEmail,$websiteId); echo $customer->getFirstname(); echo $customer->getEmail(); echo $customer->getLastname(); |
Get all customer data by below way,
echo “<pre>”;print_r($customer->__toArray());
For, Get customer data by customer id using below link, https://www.rakeshjesadiya.com/how-to-get-customer-data-by-customer-id-magento-2/