How can I modify tags for 'Very Low Stock' in product inventory?

How can I modify tags for 'Very Low Stock' in product inventory?

pullmaneditions
Visitor
2 0 0

I have products setup with a low_stock tag, made visible as 'Low stock' on website pages, similar style to how it says 'Sold out' when inventory tracker is set to 0. See here https://pullmaneditions.com/collections/all-posters

 

I want an option to also have 'Very low stock' appear, but when I do a very_low_stock_tag it just appears as 'Low stock'. I've realised this is because in my Snippets/product-price.liquid file I have the below code:

 

{% for tag in product.tags %}{% if tag contains 'low_stock' %} price--low-stock {% endif %}{% endfor %}"

I know that "contains" needs to be swapped to "==" so it gives "Low stock" and then a new statement is needed specific for very_low_stock so that each line is specific to each tag. When I have tried doing this it doesn't seem to change.

 

Please can someone help - have been stuck for ages!

Replies 3 (3)

theycallmemakka
Shopify Partner
1806 437 471

Hi @pullmaneditions ,

 

I have modified your code to work for "very_low_stock". This code will trigger correctly for both "very_low_stock" and "low_stock".

{% for tag in product.tags %}
  {% if tag contains 'very_low_stock' %} 
  price-very-low-stock
  {% elsif tag contains 'low_stock'%}
  price--low-stock          
  {% endif %}
{% endfor %}

 

If you require further help to implement this code on your site, feel free to contact me.

 

Thank you

Support Me: Buy me a Coffee


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

pullmaneditions
Visitor
2 0 0

Thank you for this! It still doesn't seem to be working. I have pasted the code you altered. I will paste below the code I have now got on this Snippet...

 

{% comment %}
Renders a list of product's price (regular, sale, unit)
Accompanies product forms and meant to be updated dynamically
Accepts:
- variant: {Object} Variant Liquid object (optional)
- product: {Object} Product Liquid object (optional)

Usage:
{% include 'product-price', variant: current_variant, product: product %}
{% endcomment %}
{%- liquid
if variant.title
assign compare_at_price = variant.compare_at_price
assign price = variant.price
assign available = variant.available
else
assign compare_at_price = 1999
assign price = 1999
assign available = true
endif

assign money_price = price | money
-%}

<div id="product-price" class="price
{% if available == false %} price--sold-out {% endif %}
{% if compare_at_price > price %} price--on-sale {% endif %}
{% if variant.unit_price_measurement %} price--unit-available {% endif %}
{% for tag in product.tags %}
{% if tag contains 'very_low_stock' %}
price-very-low-stock
{% elsif tag contains 'low_stock'%}
price--low-stock
{% endif %}
{% endfor %}"
data-price
>

{%- comment -%}
Explanation of description list:
- div.price__regular: Displayed when there are no variants on sale
- div.price__sale: Displayed when a variant is a sale
- div.price__unit: Displayed when the first variant has a unit price
- div.price__availability: Displayed when the product is sold out
- div.price__low: Displayed when the product is low availability
{%- endcomment -%}
<div class="price__pricing-group">
<dl class="price__regular">
<dt>
<span class="visually-hidden visually-hidden--inline">{{ 'products.general.regular_price' | t }}</span>
</dt>
<dd>
<span class="price-item price-item--regular" data-regular-price>
{{ money_price }}
</span>
</dd>
</dl>
<dl class="price__sale">
<dt>
<span class="visually-hidden visually-hidden--inline">{{ 'products.general.sale_price' | t }}</span>
</dt>
<dd>
<span class="price-item price-item--sale" data-sale-price>
{{ money_price }}
</span>
</dd>
<dt>
<span class="visually-hidden visually-hidden--inline">{{ 'products.general.regular_price' | t }}</span>
</dt>
<dd>
<span class="price-item price-item--regular" data-regular-price>
{{ compare_at_price | money }}
</span>
</dd>
</dl>
<div class="price__badges">
<span class="price__badge price__badge--sale" aria-hidden="true">
<span>{{ 'products.general.sale' | t }}</span>
</span>
<span class="price__badge price__badge--sold-out">
<span>{{ 'products.product.sold_out' | t }}</span>
</span>
<span class="price__badge price__badge--low-stock">
<span>{{ 'products.general.low_stock' | t }}</span>
</span>
</div>

{%- if cart.taxes_included or shop.shipping_policy.body != blank -%}
<div class="product__policies rte" data-product-policies>
{%- if cart.taxes_included -%}
{{ 'products.product.include_taxes' | t }}
{%- endif -%}
{%- endif -%}
</div>

</div>
<dl class="price__unit">
<dt>
<span class="visually-hidden visually-hidden--inline">{{ 'products.product.unit_price_label' | t }}</span>
</dt>
<dd class="price-unit-price">
{%- capture unit_price_separator -%}
<span aria-hidden="true">/</span><span class="visually-hidden">{{ 'general.accessibility.unit_price_separator' | t }}&nbsp;</span>
{%- endcapture -%}
{%- capture unit_price_base_unit -%}
<span data-unit-price-base-unit>
{%- if variant.unit_price_measurement -%}
{%- if variant.unit_price_measurement.reference_value != 1 -%}
{{- variant.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ variant.unit_price_measurement.reference_unit }}
{%- endif -%}
</span>
{%- endcapture -%}

<span data-unit-price>{{ variant.unit_price | money }}</span>{{- unit_price_separator -}}{{- unit_price_base_unit -}}
</dd>
</dl>
</div>

theycallmemakka
Shopify Partner
1806 437 471

Hi @pullmaneditions ,

 

I reviewd the code snippet you provided but i cannot help and provide information based on this single file. In this code snippet, you are just adding a class. I do not see a code for  Low Stock Tag.

 

To add this feature, I will have to look into the theme and other files that render the tag.

 

Support Me: Buy me a Coffee


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com