Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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 made
This works
This doesn't work
Solved! Go to the solution
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/
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/
I think this did the trick, thanks!
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
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.
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025