How to customize the order invoice customer e-mail

Last updated on
27 September 2018

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Upon completion of an order, Ubercart sends an e-mail message to the customer with an invoice. The message is detailed but fairly generic. There are three ways to customize it for a particular store.

The invoice is generated from a theme template. The customer invoice template file is in sites/all/modules/ubercart/uc_order/templates/uc-order--customer.tpl.php. This template file contains HTML code and PHP code that generates HTML. The PHP code has a wide variety of data available to it that it can use to generate the HTML for the invoice e-mail. Read the comments of that file for more details.

It is not a good idea to modify the template file directly. If that is done, the customizations are lost when Ubercart is updated. However, registering a copy of the template is tricky.

Preparing a theme directory

All of the methods listed below require that you put a template file into your theme directory. (See the Theming Guide for information about themes.) However, you should not put the template file into any of the standard distributed themes, including those themes built-in to Drupal (like Bartik). You may lose it when you update your theme or Drupal core!

Instead, if you are using a standard theme, you should make a subtheme of it, and use the subtheme as your site's theme. You can then put your template file into the subtheme directory. All your other site-specific theme customizations can go there, too. See Creating a subtheme for directions.

The simplest way

The simplest way to modify the invoice is to simply copy the file sites/all/modules/ubercart/uc_order/templates/uc-order--customer.tpl.php to your theme directory, modify the new copy to your liking, then clear your caches. The modified copy in your theme directory will override the one in the Ubercart module files (so long as you don't change its name).

This method does not give you additional templates. If you want to use different invoices in different situations, you need to use one of the other methods below.

The easy way

Install the Ubercart Register Invoice Templates module. This provides instructions on making custom copies of the template file, and automatically registers them.

This method lets you register and use as many different templates as you like.

The hard way

It is possible to get Ubercart to recognize custom template files, as follows:

Make a subdirectory of your theme directory named "templates".

Copy sites/all/modules/ubercart/uc_order/templates/uc-order--customer.tpl.php to the new templates directory and re-name it. The new name must match the pattern uc-order--*.tpl.php. For instance, it might be named uc-order--mysite.tpl.php.

Make a miniature module to register the template. To do this:

Create a directory called "uc_invoice" in your sites/all/modules directory.

Create a file called uc_invoice.module in sites/all/modules/uc_invoice. Assuming that your custom template is named "uc-order--mysite.tpl.php", it should contain the following code:

<?php

function uc_invoice_uc_invoice_templates() {
  return array('mysite');
}

Create a second file in sites/all/modules/uc_invoice named uc_invoice.info. It should contain the following code:

name = Ubercart Invoice Template
description = Custom Ubercart Invoice Templates
core = 7.x
package = Ubercart Invoice Template

Enable the new module at admin/modules.

Clear the cache at admin/config/development/performance.

Pull up the Rules admin page at admin/config/workflow/rules. Edit the "E-mail custom checkout notification" rule. Edit the "Email an order invoice" action. Your new invoice template will appear on the list near the bottom of the page. Select it and click the "Save" button.

Help improve this page

Page status: No known problems

You can: