creative designer

Persistent cart is an interesting concept: On one hand I like the idea of a session that expires with the device I am using. On the other I see why merchants may want a cart that acts more like a saved wishlist. Let's explore a persistent cart method that may work without any apps - just some JavaScript and cookie modification.

The Idea

This isn't a lot different to the last post that did some cookie modification for handling product page shipping costs. What we'll do here is to create a cookie with a token value that is attached to the customer. So when the customer logs in from another device that specific cart token is used and gives us a persistent cart (sort of).

Example

There's a pile of blog posts that I've smashed out recently given that I've had many hours stuck on planes without wifi. This is one of those, but a real live example using this code is yet to come. Soon. I'm thinking I'll just wrap it up in a naked Shopify theme so the only code relates to this (so no css, other js, etc)

Warning

Now before you add the code to everything you have to be aware that this is just an idea. Like a lot of the posts I make here I've not dug into the possible drawbacks.

One such drawback is that Shopify will use a new cart cookie value everything the page refreshes until it has items within it. That poses a problem when you add the example code in as is. Ugh. I'm working on a more stable script but for now you should hold off just copy and pasting any thing here.

It's still a fun learning exercise to see how you can stretch the platform. If you've got feedback on issues experienced I'd love to here them.

The Code (aka: the good stuff)

Either copy the code from the block below or grab it from the Shopify Code Snippets repo.

grabbing the Liquid JS code...

Like to work with me?

Let's talk