Item Options
Item_options
is one of the most useful and powerful tags available in CartThrob. With it, you can pull all price modifiers that have been set up in the products channel for a specific option, configured options, and options that you've added on the fly. In plain English this means that you you don't need to specifically identify options to display... this tag will figure out what's available and display the options for you. This will display information about a product's options that are available in the channel data, as well as any option that the customer has selected or that you've set dynamically.
Table of Contents
Parameters
entry_id
The entry id of the item. If the item is not in the cart yet, and doesn't have a row_id
, you'll need to pass in the entry id to find the item options stored in its channel entry. If the item IS in the cart, just pass in the row_id
.
entry_id="123"
row_id
This parameter is required if you are using this tag in the update_cart_form. This is the row_id
of the item after it's been added to the cart. Passing in the row_id
will return the item's channel data, as well as any custom configured & selected options, and will make update_cart_form
understand which item in the cart to update.
row_id="{row_id}"
field
This parameter allows you to limit which field(s) are shown. Separate multiple fields by pipe.
field="product_size"
Variables
option_field
The short name of the price modifier field, or the name of the item_option
added dynamically to the cart
product_size
option_label
The descriptive name of the price modifier field. If the option is
dynamic, this will convert something like my_item_option
to My Item
Option.
Product Size
When used with the advanced configurator field type, the field name will be output once, followed by sub options labels.
configuration_label
Only applies to the advanced configurator field type. This is the descriptive name of the configurator price modifier field.
Configurable Item
input
This will create a correctly named and formatted input field.
<input type="text" name="item_options[product_size]" value="L" />
item_options_total_results
The total number of item options available for this item
5
item_options_count
The current "count" in a loop of item options groups. For instance, the first option group would display a 1, the next would be 2, and so on for each option group
example use:
{if "{item_options_count}"==1}
show this the first time only
{/if}
Variable Pairs
options
Freeform tag, lists all options.
{options}
{option_value}: {option_name} {price}
{/options}
Sub Variables
{option_value}
{option_name} (descriptive name)
{price}
{price:numeric}
{price:plus_tax}
{price:plus_tax_numeric}
{inventory} (if available on this option)
{option_count}
{option_total_results}
{YOUR_CUSTOM_FIELD}
Sub Conditionals
{if option_first_row}{/if} First row of options
{if option_last_row}{/if} Last row of options
{if selected}{/if} If the item is selected
{if dynamic}{/if} If the item was dynamically generated (not saved in the channel entry, but added when the item was added to the cart
select
Generates a select list.
{select}
<option {selected} value="{option_value}">{option_name} {price}</option>
{/select}
Sub Variables
{option_value}
{option_name}
{price}
{selected}
Sub Conditionals
{if option_first_row}{/if} First row of options
{if option_last_row}{/if} Last row of options
{if selected}{/if} If the item is selected
Conditionals
{if dynamic}
If the item option is stored as a price modifier in the Channel entry,
then it's not dynamic. If you add it on the fly (by manually adding something like this;
item_options[customer_note]
when adding the item to the cart) then it's dynamic.
{if dynamic}{/if}
{if option_field}
Checks the item's short_name
in the channel entry (if not dynamic).
If dynamic, this checks the option's key (eg. customer_note
in the example above.)
{if option_field}{/if}
{if option_label}
Checks the item's descriptive name
{if option_label}{/if}
{if options_exist}
Used to check if the current modifier has any options set. You might have a "colors" price modifier without any colors assigned to a specific product. Using this conditional, you can hide the color option completely since there are no options created for it.
{if options_exist}{/if}
Examples
This outputs item options in a select dropdown for an item already in the cart (the row_id
parameter is set.) Each price modifier and option will get its own select dropdown.
{exp:cartthrob:item_options row_id="{row_id}" }
{select}
<option {selected} value="{option_value}">{option_name} {price}</option>
{/select}
{/exp:cartthrob:item_options}
This example outputs a list of selected options for an item already in the cart
{exp:cartthrob:item_options row_id="{row_id}" }
{options}
<label>{option_label}</label>
{if selected}
{option_name} {option_value} {price}
{/if}
{/options}
{/exp:cartthrob:item_options}
Full update cart form example. This example accounts for any option that may be set either dynamically OR set in a price modifier field in the backend.
{exp:cartthrob:update_cart_form return=""}
{exp:cartthrob:cart_items_info}
{exp:cartthrob:item_options entry_id="{entry_id}" row_id="{row_id}"}
{if dynamic}
<label>{option_label}</label>
{input}
{if:else}
{if options_exist}
<label>{option_label}</label>
{select}
<option {selected} value="{option_value}">
{option_name}{if option_price_numeric > 0} +{option_price}{/if}
</option>
{/select}
{/if}
{/if}
{/exp:cartthrob:item_options}
<input type="text" name="quantity[{row_id}]" value="{quantity}" />
<input type="checkbox" name="delete[{row_id}]" value="1" />
{/exp:cartthrob:cart_items_info}
<input type="submit" value="Update" />
{/exp:cartthrob:update_cart_form}