In my case, i have two type of customer: for local customer i will keep the firstname lastname in top link if it's connected else i want to display a custom attribute that i added in registration form so i will have instead this information and then the dropdown in top link so how to proceed please any help ? enter image description here


Please try below code

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customerRepositoryInterface = $objectManager->create('\Magento\Customer\Api\CustomerRepositoryInterface');
    $customerSession = $objectManager->create('Magento\Customer\Model\Session');
    if($customerSession->isLoggedIn()) {
        $customerId = $customerSession->getCustomer()->getId();
        $customeratt = $customerRepositoryInterface->getById($customerId);
        $customAttributeCode = 'custom_name';
        echo $cattrValue = $customeratt->getCustomAttribute($customAttributeCode); //Please echo this line when you want display custom name.
| improve this answer | |
  • thanks for your replay just one question where to put this code – Developper Magento Jan 23 '19 at 8:37
  • Override this file into your theme and put in respective <li> tag vendor/magento/module-customer/view/frontend/templates/account/customer.phtml – Satish Gumudavelly Jan 23 '19 at 10:13
  • i tried this and i get a white page with just icon of language and the label skip menu – Developper Magento Jan 28 '19 at 16:38

Turn on debug hint mode in BO and override in theme

| 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.