Multi Add To Cart Form

This tag allows you to add more than one product to your shopping cart using a single form.

Array Indexes

Each product must be given a unique array key. You can use a variable like {count}, {entry_id}, or {row_id} or manually insert a number in the index. The index numbers do not need to be sequential so long as they are unique to separate each product. Each field of data being sent along should have a matching array key to group attributes together. In the example below, 1 and 2 are used as the array keys.

Product 1
<input type="hidden" name="entry_id[1]" value="{entry_id}" />
<input type="text" name="quantity[1]"  />
<input type="text" name="item_options[1][notes]"  />

Product 2
<input type="hidden" name="entry_id[2]" value="{entry_id}" />
<input type="text" name="quantity[2]"  />
<input type="text" name="item_options[2][notes]"  />

Table of Contents

Parameters

In addition to the parameters listed here, you may also use any of the Global Form Parameters.

allow_user_price

This allows your user (or you, with a hidden field) to set a price. This is useful for items like donations. You'll have to create a form field to add the price.

<input type="text" maxlength="7" size="5" name="price">

allow_user_price="yes"
allow_user_shipping

This allows your user (or you, with a hidden field) to set the shipping cost of a product. You'll have to create a form field to add the shipping cost.

<input type="hidden" name="shipping" value="{shipping_cost_field}" />

allow_user_shipping="yes"
allow_user_weight

This allows your user (or you, with a hidden field) to set the weight of a product. You'll have to create a form field to add the weight.

<input type="hidden" name="weight" value="{weight_field}" />

allow_user_weight="yes"
on_the_fly

This allows you to add on-the-fly products (products with no entry) to your cart. All products will be marked as on-the-fly.

on_the_fly="yes"

Variables

See Global Tag Variables.

Form Fields

entry_id[x]

This is a required input field. Each product must be given a unique array key. You can use a variable like {count}, {entry_id}, or {row_id} or manually insert a number in the index.

<input type="hidden" name="entry_id[{count}]" value="{entry_id}" /> <input type="hidden" name="entry_id[0]" value="7" />

quantity[x]

Set the quantity of the item corresponding to the array key.

<input type="text" name="quantity[{count}]" value="1" /> <input type="text" name="quantity[0]" value="1" />

title[x]

Set the title of an on-the-fly product.

<input type="hidden" name="title[{count}]" value="My Product" /> <input type="hidden" name="title[0]" value="My Other Product" />

price[x]

Set the price of an on-the-fly or allow_user_price product.

<input type="hidden" name="price[{count}]" value="20" /> <input type="hidden" name="price[0]" value="10" />

shipping[x]

Set the shipping of an on-the-fly or allow_user_shipping product.

<input type="hidden" name="shipping[{count}]" value="20" /> <input type="hidden" name="shipping[0]" value="10" />

weight[x]

Set the weight of an on-the-fly or allow_user_weight product.

<input type="hidden" name="weight[{count}]" value="20" /> <input type="hidden" name="weight[0]" value="10" />

Examples

Please review the note about array indexes in the overview at the top of this page.

{exp:cartthrob:multi_add_to_cart_form return="cart_examples/single_page_checkout"}
    {exp:channel:entries channel="products" category="10"}
        Product Name: {title} {product_price}
        <input type="hidden" name="entry_id[{count}]" value="{entry_id}" />
        <input type="text" name="item_options[{count}][notes]"  />
        <input type="submit" /> 
    {/exp:channel:entries}
{/exp:cartthrob:multi_add_to_cart_form}