All things Shopify and commerce
Hi, I would like to create a code in shopify script editor which will reject the discount code on a specific product instead of on all products, please suggest.
@ayusharmaPM you can try below code to block specific product block by discount price
# ID of product you want to block
productId = 10199241991
# Runs through a loop of items in your cart
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
puts product.id
next if product.gift_card?
next unless product.id == productId
case Input.cart.discount_code
when CartDiscount::Percentage
Input.cart.discount_code.reject({message: "Cannot be used with this product"})
end
end
Output.cart = Input.cart
Hi, Yes this code is correct, But when I checkout with multiple products then it will reject discount code for all products, Which seems wrong to me it should reject discount code for only product that I have define the code.
User | RANK |
---|---|
39 | |
23 | |
21 | |
14 | |
14 |
Explore the 30-30-30 rule, a dynamic social media strategy for new businesses. Learn how t...
By Trevor Sep 20, 2023Discover how to leverage the often overlooked footer of your ecommerce site to gain custom...
By Skye Sep 15, 2023In this blog, we’ll be shining a light on Shopify Partners, Experts, and Affiliates. Who a...
By Imogen Sep 13, 2023