1

I want get customer gender value like Male or Female in magento2?

and also want to get gender attribute value like 1,2,3

text: Male, Female and Not Specified

1

You can get gender value and text:

<?php

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

//Get gender value like 1,2,3
$genderValue = $customer->getCustomAttributeText('gender')->getValue();

//Get gender text like male, female
$genderText = $customer->getResource()
->getAttribute('gender')
    ->getSource()
        ->getOptionText($customer->getData('gender'));

echo $genderText;

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.