Remove a product variant from cart with a hyperlink?

Solved

Remove a product variant from cart with a hyperlink?

Mirokuwu
Shopify Partner
16 2 1

I can add a product variant to my cart with a hyperlink:
https://mywebsite.com/cart/add?id= {{ item.id }}&quantity=1

BUT

Can I remove a product variant from my cart with a similar hyperlink?
https://mywebsite.com/cart/remove?id={{ item.id }}&quantity=1

Accepted Solution (1)

Mirokuwu
Shopify Partner
16 2 1

This is an accepted solution.

GOT IT! Here is how I made a " -1 button and +1 button" for my cart which reloads the page when you press them.

THE RESTRICTION: this only works inside of the cart

<!-- minus 1 button -->
  <a href="/cart/change?line={{ forloop.index }}&quantity={{ item.quantity | minus: 1 }}>
    -1 button
  </a>

<!-- displays item quantity -->
  {{ item.quantity }}


<!-- plus 1 button  -->
  <a href="/cart/add?id= {{ item.id }}&quantity=1">
    +1 button
  </a>


Additionally, I was able to make a dropdown quantity selector for my cart that reloads the page.

<!-- dropdown quantity selector that reloads page -->
  <select>
    <option value="" disabled selected hidden>{{ item.quantity }}</option>
      <option value="/cart/change?line={{ forloop.index }}&quantity=1">  1</option>
      <option value="/cart/change?line={{ forloop.index }}&quantity=2">  2</option>
  </select>

View solution in original post

Replies 3 (3)

Mirokuwu
Shopify Partner
16 2 1

EDIT: even though I created an acceptable workaround solution, I would still like to have my original question be solved, so that I can put a "-1 item from cart" button anywhere on my website, not just having it be limited/confined to the cart.

Mirokuwu
Shopify Partner
16 2 1

This is an accepted solution.

GOT IT! Here is how I made a " -1 button and +1 button" for my cart which reloads the page when you press them.

THE RESTRICTION: this only works inside of the cart

<!-- minus 1 button -->
  <a href="/cart/change?line={{ forloop.index }}&quantity={{ item.quantity | minus: 1 }}>
    -1 button
  </a>

<!-- displays item quantity -->
  {{ item.quantity }}


<!-- plus 1 button  -->
  <a href="/cart/add?id= {{ item.id }}&quantity=1">
    +1 button
  </a>


Additionally, I was able to make a dropdown quantity selector for my cart that reloads the page.

<!-- dropdown quantity selector that reloads page -->
  <select>
    <option value="" disabled selected hidden>{{ item.quantity }}</option>
      <option value="/cart/change?line={{ forloop.index }}&quantity=1">  1</option>
      <option value="/cart/change?line={{ forloop.index }}&quantity=2">  2</option>
  </select>

JCStart
Excursionist
28 2 1

Where in theme code does this go?