Skip to content

Instantly share code, notes, and snippets.

@imuhammadshoaib
Forked from atikju/cartDiscount.liquid
Created November 12, 2020 10:59
Show Gist options
  • Save imuhammadshoaib/f600424e957238a0a9e6cda25afda89c to your computer and use it in GitHub Desktop.
Save imuhammadshoaib/f600424e957238a0a9e6cda25afda89c to your computer and use it in GitHub Desktop.
Shopify - Apply Discount / Coupon / Promo Code on cart page
<div class="cart-promo">
<h2>ENTER A PROMO CODE</h2>
<input type="text" id="devPromo">
<a href="/checkout?discount=none" id="redemDevPromo">Apply Coupon</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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment