Display customer email on delivery notes or Prestashop invoices

Tutorial / Tip: How to display the customer email on PrestaShop PDF?

This request is quite recurrent on the official Prestashop forum so we might as well make an article to refer to it.

The need

This tutorial will explain in detail how to simply display customer email on PDF documents generated by PrestaShop during orders.

This solution will allow you to display this information at the place that suits you best by touching only the TPL of the documents without modifying the source code of PrestaShop.

PrestaShop 1.6 / PrestaShop 1.7

The application of the tip works for all versions of PrestaShop 1.6 and 1.7.

To customize the delivery notes, simply choose the one that suits you best to display the information and put the code directly on this file.

The TPL files for all PDF documents are simply located in the pdf/ directory.

Their name is simple enough to identify them:

  • delivery-slip for delivery notes
  • invoice for invoices

The complete document is composed of several TPL files, so it's up to you to test where you can best display this information.

The code to insert for the delivery notes

All these documents include the object order which corresponds to the class Order.php where you can find the data returned by this object.

In our case, we will rely on a method proposed by the Order.php class, namely public function getCustomer().

This method is not declared as static, but we can call it directly in the template file since the object order is transmitted by the class calling the TPL file.

$this->smarty->assign(array(
    'order' => $this->order,    

You just have to assign the result of the method to a new variable in your template:

{assign var="customer" value=$order->getCustomer()}

Then, in your TPL at the location you want, you will be able to display the desired customer information, in our case, the email address:

{$customer->email}

This gives the following code to place where you want:

{assign var="customer" value=$order->getCustomer()}
{$customer->email}

The code to insert for the invoices

The code for the invoices is even simpler since the customer object is passed directly to the TPL, you just need to insert the second part of the code to display the email where you want:

{$customer->email}

PrestaShop 1.5

I haven't tested this version, feel free to give feedback in comments to know if this tip applies to this version too.

Conclusion

This tutorial presents the method used to achieve the display of the desired information, it can be applied to other data in other TPL of Prestashop by studying the tables or objects transmitted to your templates.

Comments