I’ve got a link that removes an item from a cart, except that when you click that link it redirects you to the cart with the item now removed. Is it possible to make it so that you can still click it and it still does its thing but it doesn’ change the page (i.e. it doesn’t send the user to the cart)?
Note: I’m working with Liquid on Shopify
Link:
<a href="/cart/change?line={{ forloop.index }}&quantity=0" class="cart__remove">
<small>{{ 'cart.general.remove' | t }}</small>
</a>
3
Answers
You can make use of cart js instead for make your things work as you want. Here is the details on shopify cart js – cart js Reference
The best way will be to send the line item number through the CartJS.removeItem function. You can also remove a cart item by it’s id using removeItemById.
It provides cart.requestComplete event listener where you can code to reload your page after remove item request is completed.
Since you have jQuery included try adding the following script
Yes You can do
AJAX Stands for Asynchronous JavaScript and XML.
As the name suggests, it is used to deal with asynchronous data transfer.
For that,
Change the HTML to
Then add the JavaScript code
You can also use HTTP POST if you want.