Search code examples
jquerycookiesshopping-cartbusiness-catalyst

Onclick remove cookie and refresh current page


I'm trying to remove 'CartID' cookie when a user clicks a "Clear Cart" link.

So far i have the following from research:

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
</head> 

<body>
   <script>
      $.removeCookie("CartID");
   </script>
</body

Can someone help with this. How would i implement a link to remove this cookie so that the cart is cleared and the page refreshes. I'm using Business catalyst and want to place the link in a sidebar site-wide.

Cheers,


Solution

  • Assuming your link looks like:

    <a href="#" id="clear-cart">Clear Cart</a>
    

    you can do it like this:

    $("#clear-cart").click( function(e){
        e.preventDefault();
        $.removeCookie("CartID");
        location.reload();
    });