Last active
May 21, 2022 20:04
-
-
Save svaustin66/580afa8092e72dd3b38918bcd00d8e72 to your computer and use it in GitHub Desktop.
Display the Cookie stored discount code on Shopify Pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.