0
votes

I have a discount code which gives 40% discount when there are more than 50 items, but this also works if I have for example 49 items + 1 other item. I want to make the code work only for the single items that have a quantity over 50.

I assume this would be pretty straight forward if I could access this logic myself. Can someone point me into whereabouts could I find these codes for my discounts?

I would also want my discount code to give 40% for items over 50 quantity, and 50% for items over 200 quantity.

I have found something called "Shopify GraphiQL App" which, if I understand correctly, would help me to modify these discount codes internally.

Any help is appreciated.

Thanks

EDIT

I have been playing a bit with GraphiQL, and I have found the priceRule has a field called: allocationMethod (PriceRuleAllocationMethod).

The value of this is ACROSS. Would my discount code have the desired behaviour if I manage to change this to EACH?

How can I modify this, I haven't been able to find an example.

EDIT 2

I have tried the following, but for some reason the allocation method is not updated. Can someone explain to me what is happening here? enter image description here

1
You need to develop it into Shopify APP, right?Onkar
I am not sure tbh. I just want this single discount code to work as expected. I don´t need a full app able to create multiple custom discount codes.VelasArtes
I want to know you want to use in your Shopify store, or want to create it into the Shopify app?Onkar

1 Answers

0
votes

I think you can do this using Liquid in the theme.liquid file:

{% assign num = 0 %} 
{% for item in cart.items %} #finding how many items in cart
        {% capture temp %}{{ num | plus: item.quantity }}{% endcapture %}
    {% endif %}
    {% assign num = temp %}
{% endfor %}

{% assign new_num = num | plus: 0 %} #converting string to integer

{% if new_num >= 50 %}
    {% assign price = checkout.subtotal_price %}
    {{ price | times: 0.40 }} #40 percent
    {{ checkout.subtotal_price | minus: price }}
{% endif %}

Edit: Maths was wrong in first edit, that should be correct now.