Shopify themes, liquid, logos, and UX
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
Hi ,
Im looking to add text that generates a number based on the amount of colours available of that product.
So if there is a red green blue option, the collection grid page will show the primary red product, but it will also have below - available in 3 colours.
So far I have tried within product-card.liquid the below code but I keep getting 0 - it isn't processing the logic below the assign num=0
{% assign num = 0 %}
{% for option in product.options_with_values %}
{% if product.options_with_values == 'Colour' %}
{% for value in option.values %}
{% assign num = num | plus: 1 %}
{% endfor %}
{% endif %}
{% endfor %}
<p>There are {{ num }} more colours to choose </p>
Solved! Go to the solution
This is an accepted solution.
This has now worked for me :
For Dawn 2.0 (v3)
Insert the code into Snippets > main-product.liquid
I have placed this within the <div> product__info-wrapper - place it appropriately to where you would like it positioned.
I have set it to where there is 3 or less left in stock, this will appear.
{% comment %}Adds text when stock is equal to one below the price.{% endcomment %}
{% assign stock = 0 %}
{% for variant in product.variants %}
{%capture stock %}
{{ stock | plus:variant.inventory_quantity }}
{% endcapture %}
{% endfor %}
{%assign stock = stock | times:1%}
{% if stock < 3 %}
<span class="label inventory"> <strong>Only {{stock}} more left in stock!</strong> </span>
{% endif %}
Here is a screen-grab of it working :
This is an accepted solution.
This has now worked for me :
For Dawn 2.0 (v3)
Insert the code into Snippets > main-product.liquid
I have placed this within the <div> product__info-wrapper - place it appropriately to where you would like it positioned.
I have set it to where there is 3 or less left in stock, this will appear.
{% comment %}Adds text when stock is equal to one below the price.{% endcomment %}
{% assign stock = 0 %}
{% for variant in product.variants %}
{%capture stock %}
{{ stock | plus:variant.inventory_quantity }}
{% endcapture %}
{% endfor %}
{%assign stock = stock | times:1%}
{% if stock < 3 %}
<span class="label inventory"> <strong>Only {{stock}} more left in stock!</strong> </span>
{% endif %}
Here is a screen-grab of it working :
User | RANK |
---|---|
127 | |
95 | |
78 | |
54 | |
46 |
Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022Shipping can be one of the most vital parts to set up and manage your business. Understand...
By Ollie Dec 16, 2022