1

I need to fetch the value of customer address attribute just like we have product attribute

I am using Magento\Customer\Api\AddressRepositoryInterface and created the instance from it

$addressRepository = $objectManager->create("Magento\Customer\Api\AddressRepositoryInterface");
$address = $addressRepository->getById($customerId);

From $address instance, I am able to fetch the default field or attribute just like

$address->getFirstname();

The problem is, I am not able to fetch the newly created customer address attribute

For Example: My newly created customer address attribute is area but I am not able to fetch it from $address->getArea();

Any help, experience and knowledge sharing would be appreciated

1 Answer 1

2

If you have custom address attribute then you can get it's value by this:

echo $address->getCustomAttribute("area")->getValue();

This would treated as same way as customer custom attribute.

But the problem with above code is, if your attribute is dropdown, then it will return option id, not the text of option.

Hope this will resolve your issue :)

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.