How to add a clear/empty cart button in Shopify
You’d like to add a button to the cart to completely empty it. It’s simple, you simply added a link to the cart:
1 | <a href="/cart/clear" class="btn clear-cart">Empty Cart</a> |
If you want to use ajax technology, please use the code below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <script> $(function() { $('.clear-cart').on('click',function(e){ e.preventDefault(); $.ajax({ type: "POST", url: '/cart/clear.js', success: function(){ alert('You cleared the cart!'); }, dataType: 'json' }); }) }); </script> |