Create line item
The create_line_item
tag renders a form which acts as a wrapper for a single or multiple items, an item can be a variant or an extra.
Extra HTML input tags can be used to add item quantity, modifiers, adult count or start and end date.
An experience slot can be referenced to book a specific date.
input
{% form "create_line_item" %}
<input type="hidden" name="items[][variant_id]" value="**<variant.id or extra.id>**"/>
{% endform %}
output
<form action="/sites/line-items" data-form-action="create_line_item" accept-charset="UTF-8" method="post">
<input type="hidden" name="return_to" id="return_to" value="/admin/site_builder/sites/c94b650e/previews/book-tickets" autocomplete="off">
<input type="hidden" name="items[][variant_id]" value="BAh7CEkiCGdpZAY6Bk....">
</form>
Including multiple items
Multiple items can be submitted in a single form. Any additional input tags can be included below each items[][variant_id]
field as required.
{% form "create_line_item" %}
<input type="hidden" name="items[][variant_id]" value="**<variant.id or extra.id>**"/>
<input type="hidden" name="items[][quantity]" value="**<quantity>**" />
<input type="hidden" name="items[][adult_count]" value="**<adult count>**" />
<input type="hidden" name="items[][variant_id]" value="**<variant.id or extra.id>**"/>
<input type="hidden" name="items[][quantity]" value="**<quantity>**" />
<input type="hidden" name="items[][modifier_ids][]" value="**<modifier.id>**" />
<input type="submit" value="add to cart" />
{% endform %}
Extra HTML input tags
Quantity
<input type="hidden" name="items[][quantity]" value="**<quantity>**" />
Modification
Include a modifier by referencing the modifier.id.
<input type="hidden" name="items[][modifier_ids][]" value="**<modifier.id>**" />
Adult count
Specify adult count for a per-unit item or accommodation.
<input type="hidden" name="items[][adult_count]" value="**<adult count>**" />
Check-in/Check-out
Specify check-in and check-out dates for accommodation items.
<input type="hidden" name="items[][start_on]" value="**<YYYY-MM-DD>**">
<input type="hidden" name="items[][end_on]" value="**<YYYY-MM-DD>**">
Experience slot
Specify the experience slot to be booked for experience items by referencing the experience_slot.id.
<input type="hidden" name="items[][experience_slot_id]" value="**<experience_slot.id>**" />
Clear cart
Clear all existing items out of a customer’s cart before adding new items.
<input type="hidden" name="clear_cart">
Extra parameters
return_to
The create_line_item
tag will reload the customer’s current page by default on form submit. To direct a customer to a different page you can pass a URL as the value of the return_to:
param.
The following example redirects to the homepage:
input
{% form "create_line_item", return_to: '/' %}
<input type="hidden" name="items[][variant_id]" value="**<variant.id or extra.id>**"/>
{% endform %}