Add to Cart
{exp:cartthrob:add_to_cart} is a single tag that executes immediately when the template is rendered. It adds an item to the cart; it does not output an add-to-cart form or link.
This tag is useful for direct-link flows, prepopulating carts, and simple server-side add operations.
See also:
Parameters
- entry_id
- quantity
- return
- license_number
- permissions
- tax_exempt
- no_tax
- shipping_exempt
- no_shipping
- show_errors
- item_options:your_option_name
entry_id
Required. Entry ID of the product to add.
entry_id="{segment_3}"
If entry_id is missing, this tag raises the add_to_cart_no_entry_id error.
quantity
Quantity to add. Defaults to 1 when not provided.
quantity="12"
return
Optional redirect URL after processing. If omitted, no redirect occurs.
return="cart/view_cart"
license_number
If truthy, the added item is flagged for license number generation at checkout.
license_number="yes"
permissions
Optional permissions metadata saved on the added item.
permissions="members|gold"
tax_exempt
Alias for no_tax. Turns off tax calculations for this item.
tax_exempt="yes"
no_tax
Turns off tax calculations for this item.
no_tax="yes"
shipping_exempt
Alias for no_shipping. Turns off shipping calculations for this item.
shipping_exempt="yes"
no_shipping
Turns off shipping calculations for this item.
no_shipping="yes"
show_errors
Controls direct error output from this tag. Defaults to yes/true.
When show_errors is enabled and an error occurs on a non-AJAX request, the tag returns show_error(...).
show_errors="yes"
item_options:your_option_name
Set item options through tag parameters.
item_options:your_option_name="small"
item_option:your_option_name (singular) is also accepted.
Behavior and Constraints
1. Runs immediately when the template is parsed.
2. Executes start/end hooks:
- cartthrob_add_to_cart_start
- cartthrob_add_to_cart_end
3. Supports package products by building package sub-items from package field data.
4. Adds item to cart, applies optional item metadata (permissions, license_number), and saves the cart.
5. Stores flashdata (success, errors, csrf_token) for downstream use.
6. Redirects only if return is provided.
This tag is a direct add operation. For user-submitted add flows, use add_to_cart_form.
Examples
Minimal direct add with redirect (installer/stub pattern)
{exp:cartthrob:add_to_cart entry_id="1" quantity="1" return="cart_examples/single_page_checkout"}
Auto-add without redirect
{exp:cartthrob:add_to_cart entry_id="{segment_3}" quantity="1"}
<h2>You've added item {segment_3} to your cart.</h2>
Tax/shipping alias example
{exp:cartthrob:add_to_cart
entry_id="{segment_3}"
quantity="1"
tax_exempt="yes"
shipping_exempt="yes"
return="cart/view_cart"}
Item options example
{exp:cartthrob:add_to_cart
entry_id="{segment_3}"
quantity="1"
item_options:size="small"
return="cart/view_cart"}