Tips on Cart

Shopify Expert
525 0 34

So I have a customer looking to add a tip on their cart page which works awesome using this tutorial...http://www.tetchi.ca/shopify-tutorial-adding-a-tip-or-donation-to-the-cart-page/

Now the issue is when a user returns to store for any reason. The cart is now full of say 501 products if they tipped $5

Anyone have a creative idea on how to automatically clear the tip line-item from the cart when they return?

 

Trevor www.carlowseo.com
0 Likes
Shopify Partner
28 0 7

When the cart page loads, you could check the contents of the cart, see if the tip's variant id is in the cart, and if it exists remove it before displaying the cart output. This would need to be done via a script, not simply in the liquid.

0 Likes
Shopify Expert
525 0 34

Hmmm.. would make sense... any ideas on how to do that?

Trevor www.carlowseo.com
0 Likes
Shopify Partner
28 0 7

It's a matter of querying the contents of the cart via:

$.getJSON( '/cart.js', function( data ) {
});

and looking for the tip's variant ID. If it exists, you can send another ajax request to '/cart/change.js' removing the tip product and then refreshing the cart page.

0 Likes