CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Order Items

The order_items tag pair outputs purchased line-item data from the cartthrob_order_items table.

Use it to report on purchased products across one or more orders, specific products, or orders created by specific members.

See also:

Parameters

order_id

Filter by one or more order entry IDs. Separate multiple IDs with |.

order_id="123|124|125"

entry_id

Filter by one or more purchased product entry IDs. Separate multiple IDs with |.

entry_id="456|455|454"

member_id

Filter by one or more member IDs (order authors).

This parameter supports placeholders:

  • CURRENT_USER
  • {logged_in_member_id}
  • {member_id}

Examples:

member_id="CURRENT_USER"
member_id="12|34"

row_id

Filter by one or more order-item row IDs.

row_id="1001|1002"

orderby

Sort by a field in the order-item result rows.

orderby="title"
orderby="price"
orderby="quantity"

sort

Sort direction. Use asc or desc.

sort="asc"

limit

Limit the number of rows returned.

limit="10"

offset

Offset rows before applying limit. Useful for pagination.

offset="5"

variable_prefix

When tags are nested, this helps avoid variable-name clashes.

Default prefixed variables use item: (for example {item:title}). If you set variable_prefix="order_items_", you can use variables like {order_items_title} and {order_items_entry_id}.

variable_prefix="order_items_"

Variables

Core variables are available as unprefixed values and as prefixed values (item: by default).

entry_id

Entry ID of the purchased item (when available).

{entry_id}

order_id

Order entry ID for this purchased row.

{order_id}

row_id

Order-item row ID.

{row_id}

quantity

Purchased quantity for this row.

{quantity}

price

Purchase price as recorded at time of purchase (formatted output).

{price}

price_numeric

Purchase price as recorded, raw numeric output.

{price_numeric} 12

price_plus_tax

Purchase price plus tax as recorded (formatted output).

{price_plus_tax} $12.77

price_plus_tax_numeric

Purchase price plus tax as recorded, raw numeric output.

{price_plus_tax_numeric} 12.77

subtotal

price * quantity for this row (formatted output).

{subtotal}

subtotal_numeric

price * quantity for this row, raw numeric output.

{subtotal_numeric} 12

subtotal_plus_tax

price_plus_tax * quantity (formatted output).

{subtotal_plus_tax} $12.77

subtotal_plus_tax_numeric

price_plus_tax * quantity as raw numeric output.

{subtotal_plus_tax_numeric} 12.77

title

Purchased item title.

{title}

count

Current item number in this result set (starts at 1).

{count}

total_results

Total number of rows in the base result set.

{total_results}

switch

Alternate between the specified values. See the ExpressionEngine docs for details.

{switch='option_one|option_two'}

YOUR_OPTION

If you saved custom item options (for example item_options[shirt_size]), those values are available as variables such as {shirt_size}.

{your_option}

Conditionals

{if first_item}

True when the current row is the first row.

{if first_item} <table> {/if}

{if last_item}

True when the current row is the last row.

{if last_item} </table> {/if}

{if is_package}

True when the item includes package sub-items.

{if is_package} a package was purchased {/if}

{if no_results}

Shown if no rows match your filter parameters.

{if no_results}You have no orders!{/if}

Variable Pairs

item_options

Outputs all item options/custom option columns for the current row.

Useful variables inside this pair include:

  • {option_label}
  • {option_name}
  • {option_value}
  • {option_price}
  • {sub_label}
  • {configuration_label}
  • {dynamic}

    {item_options} {option_label} {option_name}: {option_value} {/item_options}

packages / package

Outputs package sub-item data. Both {packages} and {package} syntax are supported. Use sub: variables inside this pair.

{package}
<li>{sub:title}</li>
{/package}

Behavior and Constraints

  1. This is a tag pair and returns parsed row output.
  2. Base retrieval is filtered by order_id, entry_id, and member_id.
  3. The default base order is order_id, row_order ASC before optional sort parameters.
  4. row_id filtering, sorting, and limit/offset are applied in the order-items fieldtype parser layer.
  5. price, price_plus_tax, subtotal, and subtotal_plus_tax are formatted; matching *_numeric variables are raw values.
  6. Product entry variables are merged when the purchased product entry still exists.

Examples

This example outputs all order items from all matched orders.

{exp:cartthrob:order_items}
    {title} {entry_id} {quantity}
{/exp:cartthrob:order_items}

This example outputs order item data for the submitted order.

{exp:cartthrob:submitted_order_info}
    {if authorized}
    Your Order Data:
        {exp:cartthrob:order_items order_id="{order_id}" variable_prefix="items_"}
            {items_title} {items_entry_id} {items_quantity} {items_price} <br />
            {item_options}
                <div style="color:red">{option_name}: {option_value}</div>
            {/item_options}
        {/exp:cartthrob:order_items}
    {/if}
{/exp:cartthrob:submitted_order_info}

This example outputs ordered t-shirt option values for entry_id 123.

{exp:cartthrob:order_items entry_id="123"}
    {title} {entry_id} {quantity} {price} T-shirt size: {shirt_size} {if shirt_color}Shirt Color: {shirt_color}{/if}<br />
    {if no_results}
        item 123 has not been purchased
    {/if}
{/exp:cartthrob:order_items}

This example uses the default prefixed syntax (item:variable) to avoid conflicts with channel:entries variables.

{exp:channel:entries channel="orders"}
    {exp:cartthrob:order_items order_id="{entry_id}"}
        <tr class="{item:switch='odd|even'}">
            <td>
                {item:entry_id}
            </td>
            <td>
                {item:title}
                {if is_package}
                    {packages}
                        {sub:title}<br />
                    {/packages}
                {/if}
            </td>
            <td align="right">
                {item:quantity}
            </td>
            <td align="right">
                {item:price}<br />
                (w/ tax: {item:price_plus_tax})
            </td>
            <td align="right">
                {item:subtotal}<br />
                (w/ tax: {item:subtotal_plus_tax})
            </td>
            <td align="right">
                {if item:product_download_url}
                    <a href="{exp:cartthrob:get_download_link field='product_download_url' entry_id='{item:entry_id}'}">Download</a>
                {/if}
            </td>
        </tr>
    {/exp:cartthrob:order_items}
{/exp:channel:entries}