This document is for a version of Craft Commerce that is no longer supported. Please refer to the latest version →

When a cart is completed, it becomes an order. You can view orders in the Commerce → Orders section of the Control Panel.

When a cart becomes an order, the following things happen:

  1. The dateOrdered order attribute is set to the current date.
  2. The isCompleted order attribute is set to true.
  3. The default order status is set on the order and any emails for this status are sent.
  4. The order reference number is generated for the order, based on the “Order Reference Number Format” setting found in Commerce → Settings → General Settings section of the control panel.

# Order Numbers

You can identify an order in three ways. By the order number, short order number, and order reference number.

# Order Number

The order number is a hash, generated when the cart is created in the session, which exists in the users session, even before the cart is saved in the database. It exists from initial creation of the cart, for the entire life of the order.

This is different to the order reference number that is only generated after the cart has been completed and becomes an order.

We recommend using the order number when referencing the order in URLs or anytime the order is retrieved publicly.

# Short Order Number

The short order number is the first 7 characters of the order number. This is short enough to still be unique, and is a little friendlier to customers, although not as friendly as the order reference number.

# Order Reference Number

The order reference number is generated on cart completion by the ‘Order Reference Number Format’ in general settings.

This number is usually the best to use as the customer facing identifier of the order, but shouldn’t be used in URLs.

{{ object.reference }}

The ‘Order Reference Number Format’ is a mini Twig template, which will be rendered when the order is completed.

Attributes on the order can be accessed as well as Twig filters and functions, for example:

{{ object.dateCompleted|date('Y') }}-{{ id }}



Please note in the above example, the ID is the element ID, which is not sequential.

A sequential number can be generated by the use of Craft’s seq() (opens new window) Twig function, which generates a next unique number based on the name parameter passed to it.

The seq() function takes the following parameters:

  1. A key name. If this name is changed, a new sequence starting at one is started. See Craft docs for more information.
  2. An optional padding character length. For example if the next sequence number is 14 and the padding length is 8, the generation number will be 00000014

For example:

{{object.dateCompleted|date('Y')}}-{{ seq(object.dateCompleted|date('Y'), 8) }}



In the above example we have used the year as the sequence name so that we automatically get a new sequence starting at 1 when the next year arrives.