Update Cart Form (tag pair)
update_cart_form updates existing cart rows, removes rows, and can save customer/session cart data (customer fields, shipping option, and custom data) in the same submission.
A video tutorial on this tag is available..
See also:
- customer_info
- save_customer_info_form
- cart_items_info
- get_shipping_options
- item_options
- delete_from_cart_form
- Global Form Parameters
Row ID Indexing
Update fields for cart items must be keyed by the cart row ID.
Use {row_id} from cart_items_info:
<input type="text" name="quantity[{row_id}]" value="{quantity}">
<input type="checkbox" name="delete[{row_id}]">
<input type="text" name="item_options[{row_id}][notes]" value="{item_options:notes}">
For package sub-items, use a parent_row_id:sub_row_id index for updatable sub-item fields:
<input type="text" name="quantity[{row_id}:{sub:row_id}]" value="{sub:quantity}">
<input type="text" name="item_options[{row_id}:{sub:row_id}][size]" value="{sub:item_options:size}">
Parameters
Tag-level form data for update_cart_form includes return and secure_return.
Additional form behavior (validation, inline errors, required/rules, action overrides, etc.) comes from Global Form Parameters.
Commonly used with update_cart_form:
returnsecure_returnerror_handlingshow_errorsrequiredrules:*actionsecure_actionidclassnameonsubmitlogged_out_redirect
What this form may change
Posted item fields that apply by default:
quantity[{row_id}]delete[{row_id}]item_options[{row_id}][…]
Posted cart / session fields that apply by default (no extra parameter):
coupon_codeshipping_optionshipping[key](saved shipping info, not an item amount)- customer fields
custom_data[key]clear_cart
Posted item fields that apply only if you opt in (rare):
price[{row_id}]— requiresallow_user_price="yes"shipping[{row_id}]— requiresallow_user_shipping="yes"weight[{row_id}]— requiresallow_user_weight="yes"
Leave those three parameters off on a normal cart. Quantity,
options, and remove are enough. A price, shipping amount, or weight
stored at add-to-cart is kept; omitting the parameters does not clear
it. A posted price[{row_id}] without allow_user_price="yes" is
ignored.
Turn them on only when this cart page is supposed to change those amounts. The usual case is a donation already in the cart: the donor should be able to change the amount. Most stores never need that.
Posted item fields that never apply here, even if present:
title[{row_id}]no_tax/tax_exemptno_shipping/shipping_exempt
Posting one of these fields for a cart row leaves the item unchanged and writes a daily Developer Log entry saying the field is ignored.
To change the intended behavior:
- For a catalog product, change the entry’s field mapped as Tax Exempt or Shipping Exempt. CartThrob reads these fields at every calculation.
- For an on-the-fly item, set
no_tax=/no_shipping=onadd_to_cart_form; the item carries those settings from then on. See Tax and Shipping Exemption Parameters. - To replace settings carried by an item already in the cart, remove it and add it again through an
add_to_cart_formon the cart page. - For a tax-free checkout as a whole, set
tax="0"oncheckout_form. - For a ship-or-pick-up choice, use a checkout shipping option rather than an item flag.
allow_user_price
Rare. Allows posted price[{row_id}] to update that cart item’s
price. Same idea as
add_to_cart_form
allow_user_price: it changes the stored item price. It is not
checkout_form allow_user_price,
which replaces the payable order total without repricing rows.
Use this when the cart should let someone change a donation amount (or another on-the-fly price). Do not enable it on a normal product cart.
allow_user_price="yes"
<input type="text" name="price[{row_id}]" value="{item_price:numeric}">
The browser controls this value. Enforce donation minimums, maximums, or other rules on the server when required.
allow_user_shipping
Rare. Allows posted shipping[{row_id}] to update that item’s
shipping amount. Leave this off unless the cart is supposed to change
item shipping. The item amount is used only with Defined Per Product
shipping (no configured shipping plugin); an active shipping plugin
calculates shipping from its own settings. This is not shipping_option or
shipping[key]; those still work without this
parameter.
allow_user_shipping="yes"
<input type="text" name="shipping[{row_id}]" value="{item_shipping}">
allow_user_weight
Rare. Allows posted weight[{row_id}] to update that item’s weight.
Leave this off unless the cart is supposed to change item weight.
allow_user_weight="yes"
<input type="text" name="weight[{row_id}]" value="{item_weight}">
Advanced: encoded subscription payloads are accepted and cleaned during update processing (subscription, subscription_allow_modification, and subscription_* values such as subscription_plan_id, subscription_price, subscription_interval_units, etc.).
Variables
You may use Global Tag Variables.
update_cart_form parses globalVariables(true), so form/error variables are available when using inline error handling (for example {if errors_exist}, {errors}, {error:field}).
Use custom_data:* variables in tag content to repopulate custom data inputs.
Form Fields
- clear_cart
- quantity[{row_id}]
- delete[{row_id}]
- item_options[{row_id}][field_name]
- price[{row_id}]
- shipping[{row_id}]
- weight[{row_id}]
- coupon_code
- shipping_option
- shipping[key]
- use_billing_info
- customer fields
- custom_data[key]
clear_cart
If present, clears all cart items in this submission.
<input type="submit" name="clear_cart" value="Clear Cart">
quantity[{row_id}]
Updates item quantity for that row.
<input type="text" name="quantity[{row_id}]" value="{quantity}">
Setting quantity to 0 removes the item.
delete[{row_id}]
Marks a row for removal. Any value works (checkbox is typical).
<input type="checkbox" name="delete[{row_id}]" value="yes">
item_options[{row_id}][field_name]
Updates item option/custom option data for a row.
<input type="text" name="item_options[{row_id}][notes]" value="{item_options:notes}">
price[{row_id}]
Updates that item’s price. Ignored unless
allow_user_price="yes" is set on the tag. Most
carts should not include this field.
<input type="text" name="price[{row_id}]" value="{item_price:numeric}">
shipping[{row_id}]
Updates that item’s shipping amount. Ignored unless
allow_user_shipping="yes" is set on the tag.
Rare; most carts should not include this field.
<input type="text" name="shipping[{row_id}]" value="{item_shipping}">
This is not shipping[key] (cart shipping info).
weight[{row_id}]
Updates that item’s weight. Ignored unless
allow_user_weight="yes" is set on the tag.
Rare; most carts should not include this field.
<input type="text" name="weight[{row_id}]" value="{item_weight}">
coupon_code
Applies a coupon code after item updates are processed.
<input type="text" name="coupon_code" value="">
shipping_option
Updates the cart’s selected shipping option.
<select name="shipping_option">
{exp:cartthrob:get_shipping_options}
<option value="{option_value}"{selected}>{option_name}</option>
{/exp:cartthrob:get_shipping_options}
</select>
shipping[key]
Updates cart shipping info values saved through save_customer_info.
This does not require allow_user_shipping. That parameter only gates
per-item shipping[{row_id}].
Examples:
<input type="hidden" name="shipping[method]" value="ground">
<input type="hidden" name="shipping[eta]" value="5_days">
use_billing_info
When truthy, shipping customer fields are copied from billing fields during customer-info save processing.
<input type="checkbox" name="use_billing_info" value="1">
Customer fields
update_cart_form calls save_customer_info, so posted customer fields are saved in session/cart customer info.
Examples:
<input type="text" name="first_name" value="{customer_first_name}">
<input type="text" name="email_address" value="{customer_email_address}">
<input type="text" name="shipping_first_name" value="{customer_shipping_first_name}">
<input type="text" name="shipping_zip" value="{customer_shipping_zip}">
custom_data[key]
Saves cart custom data values.
<input type="text" name="custom_data[gift_message]" value="{custom_data:gift_message}">
Behavior and Constraints
Action flow:
- Validate form settings/rules.
- On validation failure, action completes through form builder for inline handling (
clear_cartis explicitly preserved). - Save customer info and related posted customer/shipping/custom data.
- If
clear_cartis present, clear cart items and save cart. - Otherwise, update/remove item rows based on posted row-indexed fields.
- If
coupon_codeis non-empty, apply coupon. - Run cart inventory checks.
- Complete action with success/error redirect behavior.
- Extension hooks run at start/end:
cartthrob_update_cart_startcartthrob_update_cart_end
Important notes:
clear_cartclears items only (it does not clear customer info/custom data).delete[{row_id}]internally forces that row quantity to0.- Quantity
0removes the item row. - Only existing cart row IDs are updated.
- Package sub-item updates use
parent_row_id:sub_row_idkeys. - See What this form may change for the default vs opt-in vs never-accepted item fields.
Examples
Update Quantities and Delete Rows
{exp:cartthrob:cart_items_info}
{if first_row}
{exp:cartthrob:update_cart_form return="store/view_cart"}
{/if}
<p>{title}</p>
<input type="text" name="quantity[{row_id}]" value="{quantity}" size="2">
<label>
<input type="checkbox" name="delete[{row_id}]" value="yes">
Remove this item
</label>
{if last_row}
<input type="submit" value="Update Cart">
{/exp:cartthrob:update_cart_form}
{/if}
{/exp:cartthrob:cart_items_info}
Change a donation amount (rare)
Most carts omit allow_user_price. Use it when this page should let
someone change a donation (or other on-the-fly price) already in the
cart. Without the parameter, a posted price[{row_id}] is ignored and
the amount from add-to-cart is kept.
{exp:cartthrob:cart_items_info}
{if first_row}
{exp:cartthrob:update_cart_form
allow_user_price="yes"
return="store/view_cart"}
{/if}
<p>{title}</p>
<input type="text" name="quantity[{row_id}]" value="{quantity}" size="2">
<label>Amount</label>
<input type="text" name="price[{row_id}]" value="{item_price:numeric}">
{if last_row}
<input type="submit" value="Update Cart">
{/exp:cartthrob:update_cart_form}
{/if}
{/exp:cartthrob:cart_items_info}
Update Cart + Shipping/Customer Data + Coupon
{exp:cartthrob:update_cart_form return="store/checkout" error_handling="inline"}
{if errors_exist}
<p>Please fix the highlighted errors.</p>
{/if}
{exp:cartthrob:customer_info}
<input type="text" name="shipping_first_name" value="{customer_shipping_first_name}">
<input type="text" name="shipping_last_name" value="{customer_shipping_last_name}">
<input type="text" name="email_address" value="{customer_email_address}">
<input type="text" name="shipping_zip" value="{customer_shipping_zip}">
{/exp:cartthrob:customer_info}
{exp:cartthrob:get_shipping_options}
<label>
<input type="radio" name="shipping_option" value="{option_value}"{selected}>
{option_name}
</label>
{/exp:cartthrob:get_shipping_options}
<input type="text" name="coupon_code" value="" placeholder="Coupon code">
<input type="submit" value="Update Cart and Continue">
{/exp:cartthrob:update_cart_form}
Shipping Array + Use Billing Info
{exp:cartthrob:update_cart_form return="store/checkout"}
<label>
<input type="checkbox" name="use_billing_info" value="1">
Use billing address for shipping
</label>
<input type="hidden" name="shipping[method]" value="ground">
<input type="hidden" name="shipping[eta]" value="5_days">
<input type="submit" value="Save Shipping Info">
{/exp:cartthrob:update_cart_form}
Customer-selectable values
If you decide the value, use the fixed parameter alone, such as subscription_interval_length="3"; no input is needed. If the customer decides, use a field to carry their answer and declare its allowed values with options:<param> on the form tag, or use Subscriptions’ subscription_select inside the form pair.
Selector tags declare their own lists, which CartThrob discovers and signs before rendering. For hand-written fields, selectors in embeds, or PHP-built options, declare the allowed values on the enclosing form:
options:subscription="yes:Recurring|no:One-off"
options:subscription_interval_length="1|2|3"
options:subscription_interval_units="months|years"
Declare each term in one place. Precedence is: fixed form parameter > form-tag options: > selector’s own list. A form-tag declaration replaces the selector’s list; it does not merge with it. If a selector displays an option excluded by that replacement list, choosing it produces a validation error. Fixed values ignore submitted choices for that term.
A posted value outside a declared list or failing a declared rule stops the add or update with a validation error, leaving the cart unchanged. On a cart update, one invalid row stops the entire update; there is no partial save. Undeclared protected fields are ignored. Absent or blank choices are treated as not set unless required. Render the standard form errors inside the pair:
{if errors_exist}
{errors}<p class="alert alert-error">{error}</p>{/errors}
{/if}
Hand-written fields may use readable names: subscription, subscription_interval_length, subscription_interval_units, subscription_total_occurrences, subscription_trial_occurrences, subscription_trial_interval_length, subscription_trial_interval_units, subscription_start_date, and subscription_end_date. Short names such as SUB, SI and SIU also work; if both are posted, the short name wins. List values may be plain or the encrypted values emitted by selectors and {options:<param>} variables. Ranges and any rules accept plain values only.
For example, use a hand-written <select name="subscription_interval_length"> with options:subscription_interval_length="1|3|12" on the form. Lists, inclusive ranges and any rules are supported as described below. Keep lists short. Money, Plan identity, product binding, exemptions, payment settings and permission settings cannot be made selectable this way; use documented allow_user_* settings for customer-entered amounts.
required= checks the actual posted field name. For an interval selector, use required="SI", not required="subscription_interval_length". A hand-written input named subscription_interval_length uses that readable name in required=. Row inputs likewise need their actual field name, such as SI[row_id].
If an encrypted selector value no longer decrypts after an encryption-key change, submitting the old form produces an error; reload the page to obtain a fresh form. It does not silently add a one-time item instead.
Lists, ranges and typed values
options:<param> supports three forms:
options:subscription_interval_length="1:Monthly|3:Quarterly|12:Yearly"
options:subscription_interval_length="1-24"
options:subscription_interval_length="any"
A list allows its listed values. An inclusive range allows whole numbers between its endpoints, within the term’s limits below. any allows any valid value for that term, not arbitrary text. Ranges apply only to interval length, trial interval length, total occurrences and trial occurrences. Selector tags continue declaring lists; declare a range or any on the enclosing form tag when using a hand-written input.
| Parameter | Values accepted by any |
|---|---|
subscription |
Yes/No; yes, y, true, t, on, 1 and their no, n, false, f, off, 0 counterparts, case-insensitive. Stored as yes or no. |
subscription_interval_length |
Whole number from 1 to 999. |
subscription_trial_interval_length |
Whole number from 0 to 999. |
subscription_total_occurrences |
Whole number from 0 to 999. 0 means unlimited; the first payment counts, so 12 means twelve payments in all. |
subscription_trial_occurrences |
Whole number from 0 to 999. |
subscription_interval_units, subscription_trial_interval_units |
days, weeks, months, years, case-insensitive and stored lowercase. Singular forms are not accepted. |
subscription_start_date |
A parseable date of today or later, in the site timezone. |
subscription_end_date |
A parseable date not before the submitted or fixed start; equal dates are allowed. With no submitted/fixed start, it must not be before the current time. |
For date rules, Unix timestamp strings are also accepted; parsed dates are stored as Unix timestamp strings. On cart updates, the end-date check uses a start submitted for the same row or fixed on the form, not a start already stored on the cart item. With no start, typing today as the end usually means midnight and therefore precedes the current time.
Rules read plain posted values only, with no decryption path. Use readable input names such as subscription_interval_length or subscription_start_date, or their short names. Whitespace is trimmed. Numeric rules reject decimals, negatives, exponent notation and arrays; an HTML min/max alone does not enforce the server-side rule. Blank/absent values remain not set unless required.
A rule on an ineligible or blocked key is logged and ignored; it does not open that field. Other choice keys accept lists only. {options:<param>} variable pairs render lists, but render nothing for a range or any; use your own number, text or date input for rules. Fixed parameters still win, and a form-tag rule replaces the selector’s declaration for that key.
Discovery can be disabled with cartthrob_form_choice_discovery; explicit options: declarations still work. Add-on authors can use the form-authority developer guide.
In a cart-item loop, pass row_id="{row_id}" to every selector. It generates names such as SI[{row_id}]. Hand-written fields may use subscription_interval_length[{row_id}]. Choices apply only to their row. Plan rows keep their Plan billing terms; a tampered declared choice still produces a validation error before any update.