Link Search Menu Expand Document

Add line items to the cart

To add an item to a customer’s cart you must include a create_line_item tag

syntax
{% for item in product.variants %}
    {% form "create_line_item" %}
        <input type="hidden" name="items[][variant_id]" value="{{ item.id }}" />
        <input type="submit" value="Add to cart" />
    {% endform %}
{% endfor %}

Additional inputs should be included as relevant:

Quantity

To add more than one unit to a customer’s cart you must include a quantity input.

syntax
{% form "create_line_item" %}
    <input type="hidden" name="items[][variant_id]" value="*<variant or extra id>*" />
    <input type="hidden" name="items[][quantity]" value="*<quantity>*" />
    <input type="submit" value="Add to cart" />
{% endform %}

Modifications

Creators may choose to provide customers with additional modification options, such as the choice of a twin room or double room, or an entry time slot. Each modification should be included as an additional input on the create_line_item form.

syntax
{% form "create_line_item" %}
    <input type="hidden" name="items[][variant_id]" value="*<variant or extra id>*" />
    <input type="hidden" name="items[][modifier_ids][]" value="*<modifier id>*" />
    <input type="submit" value="Add to cart" />
{% endform %}

If a modification selection is required on a variant and one is not specified on the form the item will not be added to the customer’s cart.

Adult count

Per unit variants include a max_occupany and min_occupancy, and the price of a variant may differ based on the occupancy. To specify the adult count an additional input field is required, if no adult count is added the max occupancy will be set by default.

  <input type="hidden" name="items[][adult_count]" value="*<adult count>*" />

Start on / End on

Accommodation variants require a check-in and check-out date to be defined on the form. These are defined using start date and end date input fields. Dates should be formatted as YYYY-MM-DD.

  <input type="hidden" name="items[][start_on]" value="*<YYYY-MM-DD>*">
  <input type="hidden" name="items[][end_on]" value="*<YYYY-MM-DD>*">

Clear cart

In some instances you may want to clear all existing items out of a customer’s cart before adding new items, this can be done by adding a clear_cart input field.

  <input type="hidden" name="clear_cart">