Can anyone please tell me how to put customer's first and last name into the header in OpenCart 2.0?
I am already using this code for OpenCart 1.5.6:
<?php echo $this->customer->getFirstName(); ?>
<?php echo $this->customer->getLastName(); ?>
But this code is not working for OC 2.0
I am getting this error : Undefined property: Loader::$customer in header.tpl
Please help me anyone.
To fix this error you need to call them in the controller instead of in the template.
In catalog/controller/common/header.php add the following code inside the index() function:
$data['customer_firstname'] = $this->customer->getFirstName();
$data['customer_lastname'] = $this->customer->getLastName();
In catalog/view/theme/your-theme/template/common/header.tpl you can echo the first and last name:
echo $customer_firstname;
echo $customer_lastname;
Note that it is better not to edit Opencart core files. Instead you can use VQMod to implement the changes in the header controller.
Hey I had a solution to add first name last name of logged in user :
1.Go To: catalog/controller/common/header.php
Then find public function index () {....
Then add the following code:
if ($this->customer->isLogged()) {
$data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}
Now go to : catalog/view/theme/YOURTHEME/template/common/header.tpl
then put this where you want :