Cookies
Create, update, delete and read cookies.

cookieCreate

Creates a cookie. Requires name {string}, value {string}, and days {number}. Also used for updating and deleting cookies.
1
import {cookieCreate} from '@elkfox/shopify-theme/scripts/cookies';
2
​
3
const someCookie = cookieCreate('some_cookie', 'test_value', 30);
4
​
5
someCookie();
Copied!

Update cookies

Cookies are updated the same way they are created.
1
const updatedCookie = cookieCreate('some_cookie', 'some_new_value', 5);
2
​
3
updatedCookie();
Copied!

Deleting cookies

Assign the days variable as a negative number.

cookieRead

Retreive values from a cookie.
1
import {cookieRead} from '@elkfox/shopify-theme/scripts/cookies';
2
​
3
cookieRead('some_cookie');
Copied!

cookieTest

Test for cookie support, replacing a class from your document HTML object, when found, with a new class.
The first variable is the default class {string}, that should be added to your HTML (theme.liquid). Defaults to `no-cookies`
theme.liquid
1
<html class="no-cookies">
Copied!
The second variable is the class {string} that will replace the initial value. Defaults to `cookies`
1
import {cookieTest} from '@elkfox/shopify-theme/scripts/cookies';
2
​
3
cookieTest('no-cookies', 'cookies');
Copied!
When cookies are supported by the user's browser, the class applied to the HTML object will changed:
1
<html class="cookies">
Copied!