How to display customer name in header after logged in
-
11-12-2020 - |
Question
How can I display customer name in the header after logged in successfully?
Solution
Go to your current theme and your current header, some themes uses different headers : app/design/frontend/default/themek/template/page/html/header.phtml
for exemple then add this:
<?php if ( Mage::getSingleton('customer/session')->isLoggedIn() ): ?>
<div class="customer-name">
<?php echo Mage::getSingleton('customer/session')->getCustomer()->getName(); ?>
</div>
<?php endif; ?>
OTHER TIPS
Try this:
EDIT: file location: app/design/frontend/your_package/your_theme/template/page/html/header.phtml
Add these in this file where you want to get the name to be shown.
<?php if (Mage::getSingleton('customer/session')->isLoggedIn()): ?>
<?php echo Mage::getSingleton('customer/session')->getCustomer()->getName() ?>
<?php endif; ?>
When the customer is logged in, you can get customer session in frontend from any phtml file.
To show customer name in header, you would need to open header.phtml file located at:
app/design/frontend/yourpackage/yourtheme/template/page/html/
folder and write below code where you want to display current logged in customer name:
<?php
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
echo Mage::getSingleton('customer/session')->getCustomer()->getName();
}
?>
Please let me know if you find any problem.