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 ?
-
overwrite the template– Philipp SanderJan 22, 2019 at 15:04
-
waht template please– Developper MagentoJan 22, 2019 at 15:08
-
check my update question please– Developper MagentoJan 22, 2019 at 15:10
Add a comment
|
2 Answers
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.
}
?>
-
thanks for your replay just one question where to put this code Jan 23, 2019 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
Jan 23, 2019 at 10:13 -
i tried this and i get a white page with just icon of language and the label skip menu Jan 28, 2019 at 16:38