0

How can I display customer name in the header after logged in successfully?

3 Answers 3

2

Go to your current theme and your current header, some themes uses different headers : app/design/frontend/default/themek/te‌​mplate/page/html/hea‌​der.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; ?>
11
  • Customer name display only in account page, i need to display in header part also like, eg: Hi, Customer_Name
    – zus
    Commented 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.
    – zus
    Commented 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?
    – zus
    Commented Sep 5, 2017 at 6:26
  • 1
    <?php echo 'Hi'.'&nbsp;'.Mage::getSingleton('customer/session')->getCustomer()->getN‌​ame(); ?>
    – PЯINCƎ
    Commented Sep 5, 2017 at 7:41
3

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; ?>
4
  • Where i can add these lines
    – zus
    Commented Sep 4, 2017 at 13:03
  • @zus see my edited answer. Commented Sep 4, 2017 at 13:09
  • I need the message display at the header, like eg: hi, customer name.
    – zus
    Commented 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
1

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.

3
  • app/design/frontend/default/theme/template/page/html, name display only in account page, not header page.
    – zus
    Commented 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
    – zus
    Commented Sep 4, 2017 at 13:30
  • Please see updated answer. I have fixed the error. Commented Sep 4, 2017 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.