Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Automatic Discount Application for direct checkout

Automatic Discount Application for direct checkout

mavsalqueza
Shopify Partner
16 0 6

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 6

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 5

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
7450 657 1565

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

 

 

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


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

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