Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-22T08:53:33.680Z
Answers.Text: 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?
Answers.UserDisplayName: Bart Rylant
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-22T07:45:43.200Z
Answers.LastActivityDate: 2020-12-22T07:45:43.200Z
Answers.UserDisplayName: ZealousWeb
Body: <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>
  
Tags: <plugin-craftcommerce><plugin-craftcommerce3>
Title: Remove item from cart
ThreadText: # 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:
  
  ```
  <input type="hidden" name="purchasableId" value="{{ variant.id }}" id="{{ variant.sku }}">
  <input type="submit">
  
  ```
  
  (variant is an item from product.variants)
  
  However, when I want to remove an item, I do it like this:
  
  ```
  <input type="hidden" name="lineItems[{{ variant.id }}][qty]" value="0">
  <input type="submit">
  
  ```
  
  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 %}
  <form method="post">
      {{ csrfInput() }}
      {{ actionInput('commerce/cart/update-cart') }}
      {% for item in cart.lineItems %}
          <input type="number" name="lineItems[{{ item.id }}][qty]" min="1" value="{{ item.qty }}">
          <input type="text" name="lineItems[{{ item.id }}][note]" placeholder="My Note" value="{{ item.note }}">
          <input type="checkbox" name="lineItems[{{ item.id }}][remove]" value="1"> Remove item<br>
      {% endfor %}
      <button type="submit">Update Line Item</button>
  </form>
  
  ```
  
  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?  
  
  ---
  
  