less than a minute read • Updated 20 minutes ago
Create a bundled product
How to add a parent and child product to the cart together using bundled product relationships.
A bundled product uses a parent/child relationship — the child product is attached to the parent and cannot be managed independently in the cart. Use this when products must be sold together, such as a main product with an included accessory or add-on.
How to set it up
Use the parent_code parameter on the child product, set to match the code of the parent product. Both products are added in a single form using integer prefixes (1:, 2:) to separate them:
<form action="https://YOURSUBDOMAIN.foxycart.com/cart" method="post">
<input type="hidden" name="name" value="Parent product" />
<input type="hidden" name="price" value="19.99" />
<input type="hidden" name="code" value="741" />
<input type="hidden" name="2:name" value="Child product" />
<input type="hidden" name="2:price" value="0.00" />
<input type="hidden" name="2:parent_code" value="741" />
<input type="submit" value="Add to cart" />
</form>
The same can be done with a link:
https://YOURSUBDOMAIN.foxycart.com/cart?name=Parent+product&price=19.99&code=741&2:name=Child+product&2:price=0.00&2:parent_code=741
Making the child product optional
To make the child product optional, set 2:quantity to 0 and add a checkbox for the customer to add it:
<form action="https://YOURSUBDOMAIN.foxycart.com/cart" method="post">
<input type="hidden" name="name" value="Parent product" />
<input type="hidden" name="price" value="19.99" />
<input type="hidden" name="code" value="741" />
<input type="hidden" name="2:name" value="Optional child product" />
<input type="hidden" name="2:price" value="1.99" />
<input type="hidden" name="2:parent_code" value="741" />
<input type="hidden" name="2:quantity" value="0" />
<label>
<input type="checkbox" name="2:quantity" value="1"> Also add the optional child product ($1.99)
</label>
<input type="submit" value="Add to cart" />
</form>
Notes
When a parent product is deleted from the cart, all child products attached to it are deleted too.
To prevent the child product from being removed or adjusted independently, set
quantity_min=1— see Prevent child products from being removed.If adding multiple bundles of the same product, use a unique
codefor each parent to prevent child products from being shared across bundles.The
parent_codevalue can match either the original parent code or the modified parent code on the initial add-to-cart. On subsequent requests, children must use the modified parent code.