简体   繁体   中英

Shopify auto apply discount code by cookie?

in shopify there is an option for share link for auto applying coupon:

like https://myshopify.com/discount/COUPON

How is this working? I saw it add a cookie discount_code I tried to add it manually

function setCookie(name, value, days) {
    var expires = "";
    if (days) {
      var date = new Date();
      date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
      expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "") + expires + "; path=/";
  }

setCookie("discount_code","COUPON",7)

but it's only working with the link? How to do the same with js?

I do not think there is any such route or endpoint at any Shopify store. /discount is almost certainly a typo and not supported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM