-
-
Save andreibabor/6748270634c692f7643028f5a470cef8 to your computer and use it in GitHub Desktop.
Shopify Discout code Autofill via URL
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
<script> | |
/* Put this in theme.liquid, preferably right before "</body>" */ | |
(function() { | |
var discountParam = document.location.search.match(/discount=(\w+)/); | |
if (discountParam && discountParam.length > 1) { | |
document.cookie = discountParam[0]; | |
} | |
})(); | |
</script> |
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
<script> | |
/* | |
Put this in cart.liquid, preferably at the bottom of the file. | |
Also, make sure your cart's "<form>" has an ID of "cartform". | |
*/ | |
(function() { | |
var discountCookie = document.cookie.match(/discount=(\w+)/); | |
if (discountCookie && discountCookie.length > 1) { | |
document.getElementById('cartform').action = '/cart?' + discountCookie[0]; | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
more information https://ecommerce.shopify.com/c/shopify-discussion/t/autofill-discount-via-url-a-step-by-step-walkthrough-eg-auto-apply-discount-code-using-a-link-266537