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 :-)
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
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;