Remove line items

Remove one or more line items from a customer's cart.

Use the remove_line_item form tag to remove items from a customer's cart.

Basic usage

Loop through the cart items and submit the ID of the item to remove.

{% for item in cart.items %}
  {% form "remove_line_item" %}
    <input
      type="hidden"
      name="items[]"
      value="{{ item.id }}"
    />

    <input type="submit" value="Remove" />
  {% endform %}
{% endfor %}

Submitting the form removes the specified line item from the cart.

Removing multiple items

To remove multiple line items in a single request, include multiple items[] inputs.

{% form "remove_line_item" %}
  <input type="hidden" name="items[]" value="{{ cart.items[0].id }}" />
  <input type="hidden" name="items[]" value="{{ cart.items[1].id }}" />

  <input type="submit" value="Remove selected items" />
{% endform %}

Redirect after removing items

By default, the customer is returned to the current page after the form is submitted.

To redirect the customer elsewhere, use the return_to parameter.

{% form "remove_line_item", return_to: "/cart" %}
  <input type="hidden" name="items[]" value="{{ item.id }}" />
  <input type="submit" value="Remove" />
{% endform %}

Developer considerations

When implementing remove actions:

  • Submit the cart item's id, not the product or variant ID.
  • Use one items[] input for each line item to remove.
  • Use the return_to parameter to control where customers are redirected after the item is removed.
  • Ensure the UI clearly indicates which item will be removed before the form is submitted.

On this page