How can I display customer name in the header after logged in successfully?
3 Answers
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; ?>
-
Customer name display only in account page, i need to display in header part also like, eg: Hi, Customer_Name– zusCommented Sep 5, 2017 at 6:07
-
No, with this code the customer name will be displayed in all pages because we added it in header and the header is displayed in all pages no ? Or you want to display it just in account page ?– PЯINCƎCommented Sep 5, 2017 at 6:20
-
I need, customer name display on all pages at the header. but your code customer name display only in the account page.– zusCommented Sep 5, 2017 at 6:23
-
actually my mistake, I placed as a wrong position. now okay, but its display like below the menu bar. how can I display on the top header?– zusCommented Sep 5, 2017 at 6:26
-
1
<?php echo 'Hi'.' '.Mage::getSingleton('customer/session')->getCustomer()->getName(); ?>
– PЯINCƎCommented Sep 5, 2017 at 7:41
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; ?>
-
-
-
I need the message display at the header, like eg: hi, customer name.– zusCommented Sep 4, 2017 at 13:13
-
please open the
header.phtml
and find the place. then add the code.. Can't tell you the exact location in the file.. its up to you Commented Sep 4, 2017 at 13:19
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.
-
app/design/frontend/default/theme/template/page/html, name display only in account page, not header page.– zusCommented Sep 4, 2017 at 13:28
-
Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/root/public_html/app/design/frontend/default/themek/template/page/html/header.phtml on line 176 how to solve this error– zusCommented Sep 4, 2017 at 13:30
-
Please see updated answer. I have fixed the error. Commented Sep 4, 2017 at 13:50