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

asked Nov 20, 2019 at 7:31

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 :)

answered Nov 20, 2019 at 7:36
4
  • 1
    It looks great, let me check whether it is working or not Commented Nov 20, 2019 at 7:38
  • 1
    It worked like a charm :) Commented Nov 20, 2019 at 7:47
  • Good to hear that. +1 for answer acceptance :) Commented Nov 20, 2019 at 7:48
  • Do you know about this? magento.stackexchange.com/q/296226/77631 Commented Nov 20, 2019 at 8:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.