Access Cookies In Scripts

Conjured_Char
Shopify Partner
16 0 0

In this forum topic, one of the Shopify Experts mentions it's possible to access coookies from the script editor. Can someone give me an example of how to do that?

Thanks!

0 Likes
Gavin_Ballard1
Explorer
66 0 28

I don't think the user giving the answer in that post fully understood the context of the question. Shopify Scripts run on the back end of Shopify servers so they definitely won't have access to anything like a cookie, which exists only in the client's browser.

You could achieve something along these lines by:

(1) Using Javascript to insert a custom, hidden line item property to any add to cart forms on your site if customers have a specific cookie in their browser;

(2) On the backend, have your Shopify scripts read that line item property and perform custom behaviour based on that.

Author of http://gavinballard.com/mastering-shopify-themes/ and http://bootstrapforshopify.com.
0 Likes
Conjured_Char
Shopify Partner
16 0 0

Hi Gavin,

Thanks for the suggestion. Only thing is, if I added a hidden line item (same thing as a hidden product, right?), wouldn't that be visible in their order summary? I need the value to be hidden from the customer.

Thanks!

0 Likes
Gavin_Ballard1
Explorer
66 0 28

The standard approach to "hide" line item properties is to prefix them with an underscore (eg "_cookie"), then update your theme and email templates to avoid showing customers these values.

Author of http://gavinballard.com/mastering-shopify-themes/ and http://bootstrapforshopify.com.