How to Get Custom Customer Attribute Value in Magento 2
Magento 2 stores being the preferred choice for the majority of the E-commerce business of various types, developers have to be ready to implement any functionalities out of the blue!
One such thing that I faced was in a B2B Magento 2 store development. The B2B registration status value was required to send the registration acknowledgment or rejection Email to the customers. For that, I wanted to get the value of custom customer attribute “Account Status”. Hence, I came up with the below solution.
In other cases where you would want to get custom customer attribute value in Magento 2 stores is integration with 3rd party APIs. The APIs would return the customer attributes value which is not the part of the default Magento 2 and you’d want to use them further and require these custom attributes values.
Method to get custom customer attribute value in Magento 2:
class Data extends AbstractHelper
public function __construct(
$this->customerRepository = $customerRepository;
public function getAttributeValue($customerId)
$customer = $this->customerRepository->getById($customerId);
Any doubts on the solution? I can help you with them. All you have to do is just mention them in the Comments section below and I’ll be there.
Feel free to share the post with fellow developers on social media.