Order Items
The order_items
tag makes it simple to output item data stored in the order_items
table for completed orders. You can pull data for one or
more orders, or pull order data related to one or more products. You can access information for each purchased item's order table data like you
would with standard ExpressionEngine custom field variables. Examples shown below.
Table of Contents
Parameters
order_id
This parameter pulls up data specific to one (or more) orders. Separate multiple order_ids
with a pipe "|" character.
order_id="123|124|125"
entry_id
This parameter pulls up data specific to one (or more) specific items. Separate multiple entry_ids
with a pipe "|" character.
entry_id="456|455|454"
orderby
Orders the returned data
orderby="title"
sort
Sets the sort order. Use asc, or desc for "ascending" or "decending"
sort="asc"
limit
limit the number of order items listed.
limit="10"
offset
offsets the returned items. Useful for pagination.
offset="5"
variable_prefix
When you nest tags within tags in ExpressionEngine, you may end up with mulitple items named "entryid" or "title". Using the variable prefix allows you to set a prefix that can be added to variables to reduce these variable name clashes. If you added "order_items\" variable prefix, you could then use {order_items_title}
or {order_items_entry_id}
variable_prefix="order_items_"
Variables
All variables can also be prefixed with item: in case of clashes with another EE tag. (eg: {item:title} {item:price})
- entry_id
- order_id
- quantity
- price
- price_numeric
- price_plus_tax
- price_plus_tax_numeric
- subtotal
- subtotal_numeric
- subtotal_plus_tax
- subtotal_plus_tax_numeric
- title
- count
- total_results
- switch
- YOUR_OPTION
entry_id
This is the entry id of the purchased item (if any)
{entry_id}
order_id
This is the order id of the related order
{order_id}
quantity
The purchased quantity
{quantity}
price
The purchase price. This is the price of the item at the time of purchase.
{price}
price_numeric
The price of the item as it was recorded without formatting
{price_numeric} 12
price_plus_tax
The price of the item as it was recorded plus tax with formatting (does not change even if the related entry id or tax rate changes)
{price_plus_tax} $12.77
price_plus_tax_numeric
The price of the item as it was recorded plus tax without formatting (does not change even if the related entry id or tax rate changes)
{price_plus_tax_numeric} 12.77
subtotal
The purchase price * quantity for this item. This is the price of the item at the time of purchase.
{subtotal}
subtotal_numeric
The price of the item * quantity as it was recorded without formatting
{subtotal_numeric} 12
subtotal_plus_tax
The price of the item as it was recorded * quantity plus tax with formatting (does not change even if the related entry id or tax rate changes)
{subtotal_plus_tax} $12.77
subtotal_plus_tax_numeric
The price of the item as it was recorded * quantity plus tax without formatting (does not change even if the related entry id or tax rate changes)
{subtotal_plus_tax_numeric} 12.77
title
The title of the purchased item
{title}
count
The current item number in this group of order items
{count}
total_results
Outputs the total amount of items in this group of order items.
{total_results}
switch
Alternate between the specified values. See the ExpressionEngine docs for more information on switches.
{switch='option_one|option_two'} would switch from option_one|option_two from line to line
YOUR_OPTION
If you used item_options[shirt_size]
when you added an item to the cart, {shirt_size}
will be available. If you have "size" or "color" or "material" in your order items field, you would output them with size, color, material. The item options can be any term except entry_id
, title, quantity, count, or total_results
.
{your_option}
Conditionals
{if first_item}
Helps determine if the current item is the first in the list.
{if first_item} <table> {/if}
{if last_item}
Helps determine if the current item is the last in the list
{if last_item} </table> {/if}
{if is_package}
Helps determine if the item is a package/bundled item
{if is_package} a package was purchased {/if}
{if no_results}
Shown if no orders or entries matching your parameters are found.
{if no_results}You have no orders!{/if}
Variable Pairs
item_options
This variable pair makes it easy to output all item options, even if you don't know what the option names are.
{option_label}(option group name) {option_name}
(descriptive specific option name) and {option_value}
(sku, or code value of the option) can be used within this variable pair.
{item_options}
<strong>{option_label}</strong> {option_name}: {option_value}
{/item_options}
package
Outputs data related to packages. You can access information related to the sub items using {sub:variable}
{package}
<li>{sub:title}</li>
{/package}
Examples
This example will output all order items from all orders.
{exp:cartthrob:order_items}
{title} {entry_id} {quantity}
{/exp:cartthrob:order_items}
This example will output all order data related to a customers purchase.
{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 will output ordered t-shirt sizes 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 a the alternate syntax (item:variable) to reduce variable name clashes with the channel:entries tag variables of the same name. For instance, you can refer to the order title as well as the item title using {title} (order title) and {item:title} (item title).
{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></span>
{/if}
</td>
</tr>
{/exp:cartthrob:order_items}
{/exp:channel:entries}