Order Items FieldType

NOTE: The short name of this field can be anything except items

This documentation refers to the Order Items field type. See also: Order Items dedicated tag

You can use this field type to output the content of your order items field. When using Cartthrob’s order items custom field to display data from saved orders, you can use this tag pair to display items in orders to the user, or for the store owner as a report. Simply create a tag pair with the short name of your order items custom field. In the example below, the order items field’s short name is order_items.

When using this tag, make sure you are using the short name of your order items field. It may or may not be named order_items depending on your specific configuration

Though the order_items “tag” is really a standard channel custom field, we’re treating it like a tag pair. All of the variables below are available between the {YOUR_ORDER_ITEMS_FIELD} {/YOUR_ORDER_ITEMS_FIELD} tag pair.

Table of Contents

Parameters

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"

Variables

item:entry_id

The entry_id of the item from the products channel.

{item:entry_id}

item:title

The title of the item from the products channel.

{item:title}

item:quantity

The quantity of the item ordered.

{item:quantity}

item:count

The current loop “count” of the item being displayed. (eg. 3 of 12)

{item:count}

item:price

The price of the item as it was recorded (does not change even if the related entry id changes)

{item:price} $12.00

item:price_numeric

The price of the item as it was recorded without formatting

{item:price_numeric} 12

item: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)

{item:price_plus_tax} $12.77

item: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)

{item:price_plus_tax_numeric} 12.77 

item:total_results

Displays the number items in the order.

{item:total_results}

item:switch

Alternate between the specified values. See the ExpressionEngine docs for more information on switches.

{item:switch='option_one|option_two'} would switch from option_one|option_two from line to line

item:YOUR_OPTION

If you used item_options[shirt_size] when you added an item to the cart, {item:shirt_size} will be available. If you have “size” or “color” or “material” in your order items field, you would output them with item:size, item:color, item:material. The item options can be any term except entry_id, title, quantity, count, or total_results.

{item:size}  {item:color}

Conditionals

{if item:first_item}

Helps determine if the current item is the first in the list.

{if item:first_item} <table> {/if}

{if item:last_item}

Helps determine if the current item is the last in the list

{if item: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}

If no items are found the content in this conditional will be output.

{if no_results} No items were found {/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_name} and {option_value} can be used within this variable pair. Option name will output the related field name, and option_value will output the selected value.

{item_options}
    {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

Basic Example.

Make sure you are using the short name of your order items field. It may or may not be named “order_items” depending on your specific configuration

{exp:channel:entries channel="orders"}
    {order_items}
        {item:entry_id}
        {item:title}
        {item:quantity}
    {/order_items}
{/exp:channel:entries}

Advanced Example

In this example, a table is being generated, options are being output.

{exp:channel:entries channel="orders"}
    {order_items}
        {if item:first_item}
            Total number of items: {item:total_results}.
            <table>
                <thead>
                    <tr>
                        <td>entry_id</td>
                        <td>title</td>
                        <td>quantity</td>
                    </tr>
                </thead>
                <tbody>
                {/if}
                    <tr class="{item:switch="odd|even"}">
                        <td>#{item:count}: {item:entry_id}</td>
                        <td>
                            {item:title}{if item:size} - {item:size}{/if}
                            
                            {item_options}
                                <div style="color:red">{option_name}: {option_value} </div>
                            {/item_options}
                            
                        </td>
                        <td>{item:quantity}</td>
                    </tr>
                    {if item:count == item:total_results}
                </tbody>
            </table>
        {/if}
    {/order_items}
{/exp:channel:entries}

Additional Uses

table

Display a full HTML table of the items in the order. Simply create a tag with the short name of your order items custom field, followed by :table. In the example below, the order items field’s short name is order_items.

{exp:channel:entries channel="orders"}
    {order_items:table}
{/exp:channel:entries}

total_results

Create a tag with the short name of your order items custom field, followed by :total_results. In the example below, the order items field’s short name is order_items.

{exp:channel:entries channel="orders"}
    Number of items in this order: {order_items:total_results}
{/exp:channel:entries}