A space to discuss online store customization, theme development, and Liquid templating.
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>
// 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.
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
I have the same problem. What worked until now suddenly doesn't work at all.
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?
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
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