3

I am using Magento 2.2.8 Enterprise Edition

I have a custom address attribute area a dropdown attribute with multiple options.

Now when I am getting value of attribute by using this code, I am getting ID

$address->getCustomAttribute('area')->getValue();

I just want to get Label of the selected area option, can anyone tell me How can I get it?

1 Answer 1

2

Load eavConfig via dependency Injection.

protected $eavConfig;
public function __construct(
    \Magento\Eav\Model\Config $eavConfig,
)
{
    $this->eavConfig = $eavConfig;
}

Than you can get the label like this.

$attribute = $this->eavConfig->getAttribute('customer_address', "attribute_code");
$optionlabel = $attribute->getSource()->getOptionText($attributeValue);
2
  • Thank you Arbab, I will apply this solution. Will get back to you Dec 10, 2020 at 11:11
  • 1
    worked perfectly Dec 11, 2020 at 6:47

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.