Skip to content

Instantly share code, notes, and snippets.

@svaustin66
Last active May 21, 2022 20:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svaustin66/580afa8092e72dd3b38918bcd00d8e72 to your computer and use it in GitHub Desktop.
Save svaustin66/580afa8092e72dd3b38918bcd00d8e72 to your computer and use it in GitHub Desktop.
Display the Cookie stored discount code on Shopify Pages
<div id="discount-message"></div>
<script type="text/javascript">
var codeCookieValue;
var getCookie = function(name) {
var value = "; " + document.cookie;
var parts = value.split('; '+name+'=');
if (parts.length == 2) return parts.pop().split(";").shift();
};
codeCookieValue = getCookie('discount_code');
if(!codeCookieValue){
console.log("No Discount Code");
}
if(codeCookieValue){
console.log("Discount Code - " + codeCookieValue);
document.getElementById("discount-message").innerHTML="<div class='show-discount'>Discount Code To Be Applied At Checkout: <span>" + codeCookieValue + "</span></div>";
}
</script>
@bp612
Copy link

bp612 commented Jan 26, 2021

I realize this is 3 years old, but are you still using this code? I tried it and it does pull the coupon code, but the cookie seems to linger in my browser after I've removed the coupon from my session. I also tried pulling "cart.total_discount" on the cart page but that is always 0, even if there IS a coupon applied. I can't seem to find a complete solution for this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment