Page 1 of 1

Display customer's name in the header

Posted: Mon May 24, 2010 5:50 pm
by thir13en
Hello,

How can I display the name of a logged in customer in the header?
I want to display something like Hello, John Doe.
Thank you in advance! :)

Re: Display customer's name in the header

Posted: Fri May 28, 2010 9:16 pm
by thir13en
Anyone? :(

Re: Display customer's name in the header

Posted: Fri May 28, 2010 9:21 pm
by Qphoria
Add this to the header.tpl file:

Code: Select all

<?php if ($this->customer->isLogged()) { ?>
Welcome <?php echo $this->customer->getFirstName(); ?> <?php echo $this->customer->getLastName(); ?>, Enjoy your stay!
<?php } ?>

Re: Display customer's name in the header

Posted: Sat May 29, 2010 12:47 am
by thir13en
it works!
And it's even simpler than my version!

Thanks a lot! :)

Re: Display customer's name in the header

Posted: Sat Jul 18, 2015 11:33 pm
by skydrake
it don't work in v2, which line should i put in? i tried middle, top n bottom. advice pls. thx

Re: Display customer's name in the header

Posted: Sun Aug 09, 2015 10:22 am
by javox
Anyone has any update on this? Looks as if in V2 doesn't work. Would be welcomed any clue.

Re: Display customer's name in the header

Posted: Sun Aug 09, 2015 11:08 pm
by IP_CAM
javox wrote:Anyone has any update on this? Looks as if in V2 doesn't work.
It does not need an update, in this section, because this here is the V.1.5.x - Zone.

OC v.2 is entirely different, it does not even display some WELCOME 'related' Variable, therefore,
any (similar) Welcome Section Content, defined down to the last language File, involved,
would have to be added, to make it work.
Therefore, it must be done another way, to make it work with v.2

Ernie

Re: Display customer's name in the header

Posted: Thu Aug 20, 2015 2:31 am
by Qphoria
2.0 doesn't allow direct calls to libraries from the tpl.
For 2.0 you need to add it to the controller and set a view variable.

1. EDIT: catalog/controller/common/header.php

2. FIND:

Code: Select all

public function index () {
3. AFTER, ADD:

Code: Select all

if ($this->customer->isLogged()) {
    $data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}
4. EDIT: catalog/view/theme/YOURTHEME/template/common/header.tpl

5. PUT THIS WHERE YOU WANT IT:

Code: Select all

<?php if (isset($welcome_message)) { echo $welcome_message; } ?>

Re: Display customer's name in the header

Posted: Fri Aug 21, 2015 1:02 am
by IP_CAM
After a few checks, I placed it as shown below, to make it look swell. Since my 'OC v2 like No Shop Software' uses no last name, I removed the lastName Line, and one piece of %s, to make it work:

Code: Select all

public function index() {
if ($this->customer->isLogged()) {
$data['welcome_message'] = sprintf("Welcome %s, Enjoy your stay!", $this->customer->getFirstName());
}
Question:
my public function index() { looks like this, and others look like this: public function index () {
now, wich one is written correctly, anyway !?

just to mention it!
Ernie

Re: Display customer's name in the header

Posted: Fri Aug 21, 2015 2:48 am
by IP_CAM
Just found an OC v.2 Extension for this:
http://www.opencart.com/index.php?route ... n_id=20606
Ernie

Re: Display customer's name in the header

Posted: Wed Sep 30, 2015 2:14 pm
by raunharman
This does not work for my site. I am using Opencart 2.0.1.1 with stowear theme.
Have a look at tacfabfashions.com



Qphoria wrote:2.0 doesn't allow direct calls to libraries from the tpl.
For 2.0 you need to add it to the controller and set a view variable.

1. EDIT: catalog/controller/common/header.php

2. FIND:

Code: Select all

public function index () {
3. AFTER, ADD:

Code: Select all

if ($this->customer->isLogged()) {
    $data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}
4. EDIT: catalog/view/theme/YOURTHEME/template/common/header.tpl

5. PUT THIS WHERE YOU WANT IT:

Code: Select all

<?php if (isset($welcome_message)) { echo $welcome_message; } ?>

Re: Display customer's name in the header

Posted: Mon Oct 12, 2015 1:13 pm
by raunharman
Thanks for your reply.
However I have not been able to get it right.
Could you please specify where exactly in header.tpl to put the last piece of code?

Re: Display customer's name in the header

Posted: Tue Jun 07, 2016 2:06 am
by raptorheli
Done this as described , but it is not working in OC 2.1.0.2
What is wrong here, pls advice

EDIT: catalog/controller/common/header.php

2. FIND:
CODE: SELECT ALL
public function index () {

3. AFTER, ADD:
CODE: SELECT ALL
if ($this->customer->isLogged()) {
$data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}

4. EDIT: catalog/view/theme/YOURTHEME/template/common/header.tpl

5. PUT THIS WHERE YOU WANT IT:
CODE: SELECT ALL
<?php if (isset($welcome_message)) { echo $welcome_message; } ?>

Re: Display customer's name in the header

Posted: Thu Jun 16, 2016 3:13 pm
by mephistop
raptorheli wrote:Done this as described , but it is not working in OC 2.1.0.2
What is wrong here, pls advice

EDIT: catalog/controller/common/header.php

2. FIND:
CODE: SELECT ALL
public function index () {

3. AFTER, ADD:
CODE: SELECT ALL
if ($this->customer->isLogged()) {
$data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}

4. EDIT: catalog/view/theme/YOURTHEME/template/common/header.tpl

5. PUT THIS WHERE YOU WANT IT:
CODE: SELECT ALL
<?php if (isset($welcome_message)) { echo $welcome_message; } ?>
Hi,

Add this code in catalog/language/english/common/header.php

Code: Select all

            
$_['text_logged']  = 'You are logged in as <b><a href="%s">%s</a></b> <b>(</b> <a href="%s">Logout</a> <b>)</b>';  
$_['text_welcome'] = 'Welcome visitor you can <a href="%s">login</a> or <a href="%s">create an account</a>.'; 
$_['text_welcome'] = 'Welcome!';
 
Then add this code in catalog/controller/common/header.php
after ($data['text_shopping_cart'] = $this->language->get('text_shopping_cart');)

Code: Select all

$data['text_welcome'] = sprintf($this->language->get('text_welcome'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
And then add this code in catalog/view/theme/YOUR_THEME/template/common/header.tpl

Code: Select all

<?php if ($logged) { ?>
<?php echo $text_logged; ?>
<?php } else { ?>
<?php echo $text_welcome; ?>
<?php } ?>
After all changes update modification.

Enjoy!

Re: Display customer's name in the header

Posted: Mon Jul 31, 2017 12:19 pm
by v1tr4
It doesn't work on version 2.3.0.1, i've tried with extension or adding manually but still not work.

Re: Display customer's name in the header

Posted: Fri Aug 11, 2017 8:38 am
by IP_CAM
http://www.opencart.com/index.php?route ... n_id=20606

In OC 2.3.2.0, the OcMod Extension exactly matches the Code, and would so function,
at least in an OC Default Theme.
Ernie

Re: Display customer's name in the header

Posted: Thu Sep 14, 2017 10:57 am
by sunilkumar.25
I want to display customer's name in header of custom opencart theme of open cart version3.0

Re: Display customer's name in the header

Posted: Thu Sep 14, 2017 12:24 pm
by IP_CAM
Well, try this OcMod, it's untested, since I don't use this Version, but I cross-checked
the Content with an OC v.3.0.2.0, and it should work with a Default Theme.
Good Luck! ;)
Ernie

Re: Display customer's name in the header

Posted: Thu Mar 01, 2018 7:41 pm
by askxah
Its Very Easy to Display Customer Name in Header. on (OPENCART 2.2.0)
Just add below code in catalog/controller/common/header.php

Code: Select all

 $data['firstname'] = $this->customer->getFirstName();
 $data['lastname'] = $this->customer->getLastName();
And add this code in template/common/header.tpl

Code: Select all

 
 <?php if ( $logged ) { ?>
 <span><?php echo $firstname; ?>&nbsp;<?php echo $lastname; ?></span>
 <?php } else { ?>
    <span>Sign/Register</span>
 <?php } ?>