Re: Giving specific customers a discount

Solved

How can I apply specific discount percentages to customers?

Anne-Marieke
Excursionist
42 1 4

Hi there!

A colleague of mine helped build our Shopify webshop with some adjustments in the code.

1 adjustment was that we give customers a tag and they receive a discount without having to enter a code themselves during the check out.
This looks like this:

{% if customer.tags contains '5%' %}
<input type="hidden" id="discount" name="discount" value="Customer Condition-5%">
{% else if customer.tags contains '10%' %}
<input type="hidden" id="discount" name="discount" value="Customer Condition-10%">
{% endif %}

Now we also want to apply a discount percentage of 3, 7 and 8%, but unfortunately this colleague is no longer working for us. That's why I'm trying to learn it myself now. I have already created the discounts within the Shopify webshop and given names such as 'Customer condition-3%' and copied and adjusted the code like so:

{% if customer.tags contains "3%" %}
<input type="hidden" id="discount" name="discount" value="Customer Condition-3%">
{% else if customer.tags contains "5%" %}
<input type="hidden" id="discount" name="discount" value="Customer Condition-5%">
{% else if customer.tags contains "7%" %}
<input type="hidden" id="discount" name="discount" value="Customer Condition-7%">
{% else if customer.tags contains "8%" %}
<input type="hidden" id="discount" name="discount" value="Customer Condition-8%">
{% else if customer.tags contains "10%" %}
<input type="hidden" id="discount" name="discount" value="Customer Condition-10%">
{% endif %}

But I don't think it works yet. I have about 2% knowledge of Liquid language, so it's a bit of a copy-paste gambling for me at the moment. So I have no idea if an 'if' 'else' code works like that.

Is there anyone who can point me to an error? Thanks in advance!

 

Discounts are madeDiscounts are madeThis worksThis worksThis doesn't workThis doesn't work

Accepted Solution (1)

mysticmac
Tourist
8 2 0

This is an accepted solution.

I think in Liquid it should be "elsif" not "else if". See here: https://shopify.github.io/liquid/tags/control-flow/

View solution in original post

Replies 4 (4)

mysticmac
Tourist
8 2 0

This is an accepted solution.

I think in Liquid it should be "elsif" not "else if". See here: https://shopify.github.io/liquid/tags/control-flow/

Anne-Marieke
Excursionist
42 1 4

I think this did the trick, thanks!

Emily96
Excursionist
12 0 5

has anyone been able to pass multiple discount codes within the input type ?

e.g.

Discount 5% for collection A

Discount 10% for collection B 

 

if you separate them with a comma then only the first one is passed to checkout

twinkleppc
Explorer
38 3 9

Can you share the URL of your store? I can take a look. 

It does look like calling {{ routes.cart_url }} from somewhere. Although it is hard to tell without actually looking into the theme files but I think you also need to make changes to this routes files which is getting imported. 

Ravi Thakor
Digital Marketing Specialist | twinkleppc.co
email: ravi@twinkleppc.co