{"id":585,"date":"2019-09-05T10:39:55","date_gmt":"2019-09-05T10:39:55","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/09\/05\/get-custom-customer-attribute-value-in-magento-2\/"},"modified":"2025-05-22T16:02:22","modified_gmt":"2025-05-22T10:32:22","slug":"get-custom-customer-attribute-value-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-custom-customer-attribute-value-in-magento-2\/","title":{"rendered":"How to Get Custom Customer Attribute Value in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 \u201cAccount Status\u201d. Hence, I came up with the below solution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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\u2019d want to use them further and require these custom attributes values. Another solution that becomes essential in this context is <a href=\"https:\/\/meetanshi.com\/blog\/get-customer-data-from-attribute-value-in-magento-2\/\">get customer data from attribute value in Magento 2<\/a>. This approach provides the necessary tools to efficiently extract customer data linked to specific attribute values, particularly when sourced from external APIs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Method to get custom customer attribute value in Magento 2:<\/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\nnamespace [Vendor]\\[Module]\\Helper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\Customer\\Api\\CustomerRepositoryInterface;\nclass Data extends AbstractHelper\n{\n    protected $customerRepository;\n    public function __construct(\n        Context $context,\n        CustomerRepositoryInterface $customerRepository)\n    {\n        $this->customerRepository = $customerRepository;\n        parent::__construct($context);\n    }\n    public function getAttributeValue($customerId)\n    {\n        $customer = $this->customerRepository->getById($customerId);\n        return $customer->getCustomAttribute('custom_attribute_code');\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Likewise you can also <a href=\"https:\/\/meetanshi.com\/blog\/create-custom-order-attribute-in-magento-2-and-show-it-in-admin-grid\/\">create custom order attribute in Magento 2<\/a> which will be seen in the admin grid, as order information is used to manage and fulfill online orders efficiently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the post with fellow developers on social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Recommended Read:<\/strong> <a href=\"https:\/\/meetanshi.com\/blog\/how-to-add-extra-fee-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Learn to Add Extra Fee in Magento 2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#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-585","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/585","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=585"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/585\/revisions"}],"predecessor-version":[{"id":15282,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/585\/revisions\/15282"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}