I am trying to fetch a custom attribute value of a customer in magento 2 but I am unable to fetch it
I am using \Magento\Customer\Api\CustomerRepositoryInterface
class to fetch the custom customer attribute of a customer
I have tried this
$customers = $this->customerRepositoryInterface->getById(2);
print_r($customers->getCustomAttributes('enable_alerts'));
This returns
Array (
[enable_alerts] => Magento\Framework\Api\AttributeValue Object
(
[_data:protected] => Array
(
[attribute_code] => enable_alerts
[value] => 1
)
)
)
But I need only value of enable_alerts
.
What I am doing wrong here Is there any other way of fetching customers attribute value I have tried multiple codes and searched every thing!