0

I have created customer custom attribute 'segments' with the below options:

Options: SME, Reseller, Others

I want get segments value with text based on the customer id in magento2.

How to achieve this.

Thanks in Advance :-)

0

You can get value and text by using this code:

<?php

$customerId = 12;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customer = $objectManager->create('Magento\Customer\Model\Customer')->load($customerId);

//Get segments value
$segmentsValue = $customer->getCustomAttributeText('segments')->getValue();

//Get segments text
$segmentsText = $customer->getResource()
->getAttribute('segments')
    ->getSource()
        ->getOptionText($customer->getData('segments'));

echo $segmentsText;
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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