Каждый URL на вашем веб-сайте с параметром discout будет активирован при оформлении заказа.
ПРИМЕР ИСПОЛЬЗОВАНИЯ
ваш код скидки DISCOUNTCODE1
www.myshopifywebsite.com/products/product1?discount=DISCOUNTCODE1
или
www.myshopifywebsite.com?discount=DISCOUNTCODE1
ШАГ 1
/* Put this in theme.liquid, preferably right before "</body>" inside a script tag */
//this code set the cookie
(function() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
var product = urlParams.get('discount');
if (product != null && product.length > 1) {
document.cookie = 'discount=' + product + ';path=/';
}
})();
ШАГ 2
//Insert this code in cart-template.liquid or cart.liquid at the bottom of the page inside script tag
//Also, make sure your cart's "<form>" has an ID of "cartform".
/*Function to getcookie*/
function getCookie(nome) {
var name = nome + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
(function() {
var discountCookie = getCookie('discount');
if (discountCookie != null && discountCookie.length > 1) {
document.getElementById('cart_form').action = '/cart?discount=' + discountCookie;
}
})();
ШАГ 3
//Insert this code in header.liquid (for reciving discount also in a product page), preferably at the bottom of the page inside script tag
//Also, make sure your chechout "<form>" has an ID of "checkoutgsdr".
/*Function to getcookie*/
function getCookie(nome) {
var name = nome + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
(function() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
var product = urlParams.get('discount');
if (product == null || product.length <= 1) {
var discountCookie = getCookie('discount');
if (discountCookie != null && discountCookie.length > 1) {
document.getElementById('checkoutgsdr').action = '/checkout?discount=' + discountCookie;
}
}else{
document.getElementById('checkoutgsdr').action = '/checkout?discount=' + product;
}
})();