Invoice System

The invoice system for Ubercart is really as flexible as you want it to be. An invoice is simply a representation of an order on your site that a customer can keep for their records or you can use in holding, ordering, or shipping goods. Invoices in Ubercart are displayed using the specified invoice templates in the Order settings and Notification settings configuration forms.

Ubercart ships with a couple standard invoice templates. However, developers should feel free to dive in head first and start making their own for their sites. Even folks with no PHP knowledge should be able to style the templates differently. It's very simple...

  1. Browse to the directory ubercart/uc_order/templates.
  2. Copy either customer.itpl.php or admin.itpl.php to a new file and rename it (you must keep the .itpl.php file extension).
  3. Modify the new file to your heart's content.
  4. Choose your new template in the appropriate settings menus (Store administration/Configuration/Order settings/Customer settings).

A few things to consider...

  1. Ubercart exposes different variables for you using tokens. These are bracketed words, like [site-logo] or [order-id]. Feel free to use any of these throughout your template. You can find a list of tokens on your Ubercart site at /admin/store/help/tokens.
  2. You can use PHP in these files. You can check conditions, access variables, call functions... anything you want. Ubercart does a little bit of legwork by setting the following variables for you to use before loading the invoice template:
    • $op - tells you how the invoice is being used; will be a string matching checkout-mail, admin-mail, view, or print
    • $thank_you_message - TRUE or FALSE to show a thank you message
    • $help_text - TRUE or FALSE to show a help message to your customers
    • $email_text - TRUE or FALSE to include a message specifically for e-mailed invoices
    • $store_footer - TRUE or FALSE to include a footer for your store
    • $business_header - TRUE or FALSE to include your store's info in a header
    • $shipping_method - TRUE or FALSE to include shipping method information
    • $order - the entire order object
    • $products - an array of the products copied from the order object
    • $line_items - a sorted array of all the line items displayed for the order
  3. To avoid problems with e-mailed invoices, you should use absolute URLs for any links or images.
  4. As much as your developer sense wants to avoid it, I personally have no qualms about using tables and the style attribute for HTML tags in invoices so they look right in e-mails. Maybe there's a better way to do that?
  5. Test your invoice template before going live! You don't want it to be spouting out PHP errors or malformed HTML to your customers.
  6. It would be best to give your custom templates unique names so they won't be overwritten when you update your Ãœbercart installation. It would be a bummer to lose all your work!

And please feel free to post the invoice templates you come up with in our contributions directory! There's a category specifically for Invoice related contributions.