Skip to content

Instantly share code, notes, and snippets.

@heywin
Forked from atikju/cartDiscount.liquid
Last active March 25, 2021 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heywin/708ec0e9e100d6e6a0134e3ec67b1f1a to your computer and use it in GitHub Desktop.
Save heywin/708ec0e9e100d6e6a0134e3ec67b1f1a to your computer and use it in GitHub Desktop.
Shopify - Apply Discount / Coupon / Promo Code on cart page
<div class="cart-promo">
<input type="text" id="devPromo" placeholder="Discount Code">
<a href="/checkout?discount=none" id="redemDevPromo" class="btn" style="margin-bottom:0px">Apply</a></div>
<script>$(document).ready(function() {
//listen to the promo button click
$('#redemDevPromo').on('click',
function(event) {
//disable the button event
event.preventDefault();
//write the url format
var theUrl = '/checkout?discount=';
//grab the discount code from the input
var theDiscount = $('#devPromo').val();
//full url to redirect to checkout with promo code
var toRedirect = theUrl + theDiscount;
console.log(toRedirect);
//redirect
window.location.href = toRedirect;
});
});
</script>
@heywin
Copy link
Author

heywin commented Jun 21, 2020

cart.liquid文件中添加

@sierralx
Copy link

I added to cart.liquid, looks great. When click Apply, go to checkout but coupon shows none.
Any update?

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