Want to read a particular customer attribute in Magento 2? Use the following code to retrieve an attribute value for any customer by customer ID:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
public function __construct( \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, ... ) { $this->customerRepository = $customerRepository; } $customer = $this->customerRepository->getById($customerId); $customAttr = $customer->getCustomAttribute('what_ever'); if ($customAttr) { echo $customAttr->getValue(); } |
Reading a customer attribute
Need help implementing this solution, or still looking for a fix to your Magento problem? Get in touch and I will be happy to help with your project.