Clear cart when user closes their browser

cwilliamson1111
New Member
7 0 0

Does anyone know how I can get the cart to empty when the user closes their browser? I have tried adding this to the footer:

 

<script type="text/javascript">
function del_cookie(cart) {
document.cookie = cart +
'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
</script>

 

and adding 

 

onload="SetCookie()" onunload="del_cookie()"

 

to the body tag in theme.liquid but it doesn't work. I'm not sure where I'm going wrong. If anyone can help that would be much appreciated!

0 Likes
rejina
Tourist
10 0 2

Did you ever find a solution for this? I am trying to do the same thing!

0 Likes
cwilliamson1111
New Member
7 0 0
I’m afraid not! Let me know if you figure it out because I’d still quite like to find a solution to this.
0 Likes
Reincarnated
Pathfinder
102 8 24

Hey Peeps.

 

This might be possible with Javascript, but rather than deleting the Cookie I would see about running a

https://Your-URL-Here/cart/clear

The issue with this though, is your possibly removing Shopify's ability to do abandoned carts.   Meaning no email sent to say "Hey you had stuff in your cart!"

 

This could lead to lost sales.

0 Likes
cwilliamson1111
New Member
7 0 0

Hi @Reincarnated 

 

Thanks for your suggestion! I'm not sure what you mean by running a Your-URL-Here/cart/clear though.

 

From what I've read on Shopify this would be linked to from a button that the user clicks. How would you implement this just when the user closes their browser with no other action on their part?

 

Thanks!

0 Likes
Jingle
Tourist
7 0 2

Hello!

I have the same issue.

I was about to launch my store today when I noticed after doing a test purchase that the cart was not emptied/cleared when I closed the browser. Have you found a solution yet?

0 Likes
cwilliamson1111
New Member
7 0 0
I'm afraid not. Didn't ever manage to find a solution unfortunately.
0 Likes
Jingle
Tourist
7 0 2

That's odd. 

I'm concerned because this will mess up the order. A buyer might be surprised upon check-out that there are items in the cart that they didn't intend to buy. This might result in bad customer experience

0 Likes