<p>You can remove a line item by including a remove parameter in the request. This example adds a checkbox the customer can use to remove the line item from the cart:</p>
<pre><code>{% set cart = craft.commerce.carts.cart %}
&lt;form method=&quot;post&quot;&gt;
    {{ csrfInput() }}
    {{ actionInput('commerce/cart/update-cart') }}
    {% for item in cart.lineItems %}
        &lt;input type=&quot;number&quot; name=&quot;lineItems[{{ item.id }}][qty]&quot; min=&quot;1&quot; value=&quot;{{ item.qty }}&quot;&gt;
        &lt;input type=&quot;text&quot; name=&quot;lineItems[{{ item.id }}][note]&quot; placeholder=&quot;My Note&quot; value=&quot;{{ item.note }}&quot;&gt;
        &lt;input type=&quot;checkbox&quot; name=&quot;lineItems[{{ item.id }}][remove]&quot; value=&quot;1&quot;&gt; Remove item&lt;br&gt;
    {% endfor %}
    &lt;button type=&quot;submit&quot;&gt;Update Line Item&lt;/button&gt;
&lt;/form&gt;
</code></pre>
<p>You can check more on this on craft commerce documentation by using below link.
<a href="https://craftcms.com/docs/commerce/3.x/orders-carts.html#carts" rel="nofollow noreferrer">https://craftcms.com/docs/commerce/3.x/orders-carts.html#carts</a></p>

CC BY-SA 4.0
2020-12-22T08:53:33.680Z
Thank you. Yes I found that in the docs. But that still means I need the lineItem ID for the item I want to remove. And I don't know that id, since I am on a product detail page and want to remove only that product. On the product page I only know the variant properties.

I could loop through all the lineItems and filter out the lineItem where the purchasableId = the variant id. But that doesn't sound like it is the best option there is. There must be something easier, no?
Bart Rylant
CC BY-SA 4.0
2020-12-22T07:45:43.200Z
2020-12-22T07:45:43.200Z
ZealousWeb
<p>Ok, I'm getting pretty crazy here. I'm trying to remove a variant from the cart. Adding works fine, like this:</p>
<pre><code>&lt;input type=&quot;hidden&quot; name=&quot;purchasableId&quot; value=&quot;{{ variant.id }}&quot; id=&quot;{{ variant.sku }}&quot;&gt;
&lt;input type=&quot;submit&quot;&gt;
</code></pre>
<p>(variant is an item from product.variants)</p>
<p>However, when I want to remove an item, I do it like this:</p>
<pre><code>&lt;input type=&quot;hidden&quot; name=&quot;lineItems[{{ variant.id }}][qty]&quot; value=&quot;0&quot;&gt;
&lt;input type=&quot;submit&quot;&gt;
</code></pre>
<p>But nothing gets removed. The weird thing is, when I query for lineItems, there's an item with the id &quot;92&quot;. The id from the variant is <code>19874</code>. So that's the id I use in the hidden qty field. I have absolutely no idea where this <code>92</code> comes from. It is not the variant id. It's alo snot the product id. I don't know what it is. What am I doing wrong here?</p>

<plugin-craftcommerce><plugin-craftcommerce3>
Remove item from cart
# Remove item from cart

(Asked by: username_0 on 2020-12-21)

Ok, I'm getting pretty crazy here. I'm trying to remove a variant from the cart. Adding works fine, like this:



(variant is an item from product.variants)
However, when I want to remove an item, I do it like this:



But nothing gets removed. The weird thing is, when I query for lineItems, there's an item with the id "92". The id from the variant is 19874. So that's the id I use in the hidden qty field. I have absolutely no idea where this 92 comes from. It is not the variant id. It's alo snot the product id. I don't know what it is. What am I doing wrong here?

**Tags:** plugin-craftcommerce, plugin-craftcommerce3

---

## 1 answers

### Answer by username_1 on 2020-12-22. Score: 2

You can remove a line item by including a remove parameter in the request. This example adds a checkbox the customer can use to remove the line item from the cart:
{% set cart = craft.commerce.carts.cart %}

    {{ csrfInput() }}
    {{ actionInput('commerce/cart/update-cart') }}
    {% for item in cart.lineItems %}
        
        
         Remove item
    {% endfor %}
    Update Line Item


You can check more on this on craft commerce documentation by using below link.
https://craftcms.com/docs/commerce/3.x/orders-carts.html#carts

> **Comments:**
> **username_0**: Thank you. Yes I found that in the docs. But that still means I need the lineItem ID for the item I want to remove. And I don't know that id, since I am on a product detail page and want to remove only that product. On the product page I only know the variant properties.  I could loop through all the lineItems and filter out the lineItem where the purchasableId = the variant id. But that doesn't sound like it is the best option there is. There must be something easier, no?  

---

