Create an add-to-cart form using Liquid
On this page
You can create an add to cart form using the Liquid form helper. To do this you first find the product you want to add the form for and then use the form helper to wrap your HTML code in a form.
For example:
``` {% assign product = all_products[“aloe-foaming-cleanser-100ml”] %}
{% form “add-to-cart”, product_id: product.id %}
Quantity
{% endform %} ```
If your product has variants in it, you could handle this by allowing the user to select a specific variant:
``` {% assign product = all_products[“tennis-shoe”] %}
{% form “add-to-cart”, product_id: product.id %}
Quantity
Size 37
Size 38
Size 39
Size 40
White
Multi
{% endform %} ```
Note, if the combination of options is not available due to stock or other reasons, the user will be shown the product page with an error message to select an available option.