Re: Automatic Discount Application for direct checkout

Automatic Discount Application for direct checkout

mavsalqueza
Shopify Partner
16 0 5

I used this code to redirect the customer to checkout page. It's working except the discount code is not automatically applied. Everything is working (including the automatic discount code application) last time I published the code, but now the discount code is not automatically applied. Am i missing something? No changes made on discount code setting. It just doesn't work now😞

<form method="post" action='/cart'>
  <input name='id' class='hidden' value="VARIANT_ID" type='hidden'>
  <input name='selling_plan' class='hidden'  value="SELLING_PLAN_ID" type='hidden'>
  <input name='discount' class='hidden' value="DISCOUNT_CODE" type='hidden'>
  <input name='qty' class='hidden' value="1" type='hidden'>
  <button type="submit" name="checkout">Buy Now</button>
</form>
Replies 5 (5)

webizito
Shopify Partner
77 5 6
// Define the discount percentage
var discountPercentage = 10; // 10% discount

// Get the cart total
var cartTotal = Input.cart.total_price;
if (cartTotal >= 100) {
  // Calculate the discount amount
  var discountAmount = (cartTotal * (discountPercentage / 100));

  // Apply the discount to the cart
  Input.cart.line_items.forEach(function(item) {
    item.line_price = item.original_line_price - discountAmount;
  });
}

// Output the updated cart
Output.cart = Input.cart;


Please try this Script.

Thanks.

✌ We are volunteering to help | Likes and Accept as Solution will be much appreciated.
Need a Shopify developer?  | Chat on WhatsApp | Hire us at Email: info@webizito.com || Website: www.webizito.com
mavsalqueza
Shopify Partner
16 0 5

yes I already have the computation on the cart page, but what I meant is: the discount code not automatically applied when you proceed to checkout

gord007
Shopify Partner
1 0 0

I have the same problem. What worked until now suddenly doesn't work at all.

Emily96
Excursionist
12 0 4

works on dawn 11.0

however only one discount is handed over to checkout. Is there an accepted syntax to pass multiple codes within the input type?

PaulNewton
Shopify Partner
6350 582 1356

For the frontend code as the original poster was using only one discount-code for the discount parameter as part of a cart/checout submission is used.

 

Checkout-scripts are another matter for shopify-plus stores

https://community.shopify.com/c/shopify-scripts/multiple-discounts-on-products-with-script-editor/td... 

bearing in mind checkout-scripts are being depreciated in 2024 in favor of shopify functions

 

 

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org