Reputation: 13
How to display customer id in header.tpl on Opencart 2?
if ($this->customer->isLogged()) {
$data['customer_id'] = $this->customer->getId(); // customer ID
$data['customer_fname'] = $this->customer->getFirstName(); // customer email
}
doesn`t work.
Upvotes: 1
Views: 2277
Reputation: 5092
In header.php file add this two variables
if ($this->customer->isLogged()) { // <-- This line is around 52
$this->load->model('account/wishlist');
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist());
$data['customer_id'] = $this->customer->getId(); // <-- add this variable
$data['customer_fname'] = $this->customer->getFirstName(); // <-- and this variable
} else {
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
}
In header.tpl file you can use the variables like this, must be inside the if ($logged)
block
<?php if ($logged) { ?>
<?php echo $customer_id; ?>
<?php echo $customer_fname; ?>
<?php } ?>
Tested on OC 2.2.0.0
Upvotes: 3