If a discount code "spend149" is in the user's cart, and the cart's total is $149 or more, the line items should be discounted 5%.
Only items that are tagged with the tag "coupon" get the 5% discount.
Here's the code block which achieves this:
if discount_percentage > 0
Input.cart.line_items.each do |line_item|
# if line_item.variant.product.tags.include? tag
total_value += (line_item.line_price.cents/100)
if total_value >= total_threshold
cart = Input.cart
cart.line_items.each do |line_item|
if line_item.variant.product.tags.include? tag
if discount_percentage > 0
line_discount = line_item.line_price * (discount_percentage/100)
new_price = line_item.line_price - line_discount
I was hoping to help a bit. Ive come up with an idea to apply discount only on items you want by using the cupon code as a flag to apply the discount the way you want it to apply. You just make a cupon of 0% and catch it on the script, if its the cupon your looking for then apply the discount to the products you want excluding the products you dont want. Its mainly the idea of how to do it more then the code. I know this might not be the way you all are looking for, but its a work around for now :P. HERE is the code I made. Ideas to make it better and cleaner are welcome. Im just starting on Ruby so dont be harsh haha. If you guys have any questions Ill be glad to help :D
@rickydazla Currently its not possible to make a discount cupon ignore just one line in the Cart. Though that would be awesome haha. But I did a work around for that which you can see HERE. Basically the idea is to make a 0% cupon and use it as a flag to make the discount yourself from the Scripts. For me it has worked really well. Good Luck! :D
Don't know if this would help anyone but, I created two collections and hid them from the store. 1collection was for products that we allow discounts on. The second was for items that were not allowed discounts. We then put all products in their respective collections and created a discount coupon for the specific collection. Since products can be in multiple collections it hasnt disrupted anything on our store and allows us to keep coupons from being applied to high cost, low margin items.
As long as you are creating discount codes for the collections that contain only items you want discounted then you should be fine. It doesn't matter if a discount item and a non discount item are in a separate similar collection.
Example. I have a collection called "t-shirts" with discount and non-discount items.
I create two new separate collections. One is called "discount shirts" the other is "non-discount shirts". I hide these two new collections from the store and create a discount code for "discount shirts" collection. I then put All shirts in their respective new collection.
Now only the the t-shirts in the "discount shirt" collection will allow the discount code to be applied.
I want to create a discount code that applies both to a customer in a group and a collection. Basically we have some bundles that we don't want to apply discounts to but we want to have a member discount that can be used on anything but the bundles. It doesn't look like there's a simple way to do this. Discount codes just don't have enough options.
But it almost sound like I can make a cart level rejection that will reject using the code if a Bundle is in the cart. Is this correct? Can anyone give me some pointers to how this would work?
I know this is completely wrong but here is my line of thought of what kind of code I'll need:
if discount_percentage does not equal nil
if line_item.variant.product.tags.include? bundle
cart.discount_code.reject(:message=>"No Bundles allowed with discount. Remove Bundled products and try again!")
Ive made a Shopify Scritp which uses a cupon on 0% discount as a flag to apply the discounts on the products you decide with the code you would write. You can look a the examples HERE. For the information on the client you can use the object CUSTOMER from the input.cart.customer to find if he has the necesary tags to apply the discount. Its fairly easy if you know what you want :D If you need help just reply to this message, Ill gladly help you out :P Im sure you've seen the documentation HERE for the objects you can use in Shopify Scripts. Its really usefull. PLUS they've just included the Shipping object to offer free shipping or take into account the Shipping info. Good luck! :D
|4 hours ago|
|08-22-2019 04:45 PM|
|08-22-2019 09:25 AM|
|08-22-2019 12:10 AM|
|08-19-2019 10:26 AM|