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
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 :)
- 
 1It looks great, let me check whether it is working or notMuhammad Hasham– Muhammad Hasham2019年11月20日 07:38:31 +00:00Commented Nov 20, 2019 at 7:38
- 
 1It worked like a charm :)Muhammad Hasham– Muhammad Hasham2019年11月20日 07:47:55 +00:00Commented Nov 20, 2019 at 7:47
- 
 Good to hear that. +1 for answer acceptance :)Shoaib Munir– Shoaib Munir2019年11月20日 07:48:16 +00:00Commented Nov 20, 2019 at 7:48
- 
 Do you know about this? magento.stackexchange.com/q/296226/77631Ankita Patel– Ankita Patel2019年11月20日 08:24:03 +00:00Commented Nov 20, 2019 at 8:24
Explore related questions
See similar questions with these tags.