Ricardo
Ricardo

Reputation: 1672

Discount input not working on Shopify cart page

I need a coupon code input on my cart page but it doesn't seem to work in its plain form:

<input class="discount-code-field" autocomplete="off" type="text" name="discount" placeholder="Enter coupon code here" />

I have it right before the submit button, inside the form.

Live coupons are not being applied to the order on the checkout page.

Is there anything else I need to do for it to work?

Edit: The form looks like this —

<form action="/cart" method="post" class="cart">

  ............

  <div class="bottom-box">
     <input class="discount-code-field" autocomplete="off" type="text" name="discount" placeholder="Enter coupon code here" />
     <input type="submit" value="Proceed to checkout" name="checkout" class="cart-submit w-button"/>
  </div>
</form>

And it redirects to a URL like this: https://store.com/4934605xxxx/checkouts/04d6478feeb9d3262fbea5571b682ebc?_ga=2.260083023.358228188.1608464294-110675315.1604953057

Upvotes: 0

Views: 2026

Answers (1)

drip
drip

Reputation: 12933

As long as your cart is not using AJAX to update and redirect this should work.

The checkout page accepts a get argument of ?discount= and adding a field with a name="discount" will add that argument to the checkout.

This works only if you submit the standard form directly. (if you update the cart, the field discount text will not be present and you need to re-enter it again) If you must update the form you will need to keep the discount code in some way, via updating the cart with ajax or storing it as a cookie.

So your code should be working, I double checked it on my dev store and there is no issues, it applies a discount to the checkout page since the get argument is present.

PS: This does not add a discount to the cart object, it only allows for the checkout redirect to include a get argument, nothing else. So this is equivalent to making a link with <a href="/checkout?discount=YOUR_CODE">Checkout</a>

Upvotes: 0

Related Questions