Add another condition to Inventory status - Dawn

Hi all,

I want to add another status to my inventory status on my website.

For example, by default, if it is over 5pcs in stock it displays “In Stock”, if under 5pcs it says “Low Stock”, however I want to add an additional condition that if there’s only 1pc left in stock it will say “Last Unit” with a red circle too.

Is this possible?

Screenshots for context, thanks in advance

Hello @BYS

  1. Go to Shopify Admin → Online Store → Themes Edit Code.
  2. Open the file Sections main-product.liquid
  3. Look for the existing inventory status code. It should be inside a {% if %}condition, typically checkingproduct.variants.first.inventory_quantity.
  4. Modify it to include an “In Stock” message when inventory is available.
    Find this section
{% if current_variant.inventory_quantity > 0 %}
  

{{ 'products.product.stock_available' | t }}

{% endif %}
​

Modify it like this to display “In Stock”

{% if current_variant.inventory_quantity > 0 %}
  

In Stock

{% elsif current_variant.inventory_policy == 'continue' %}
  

Available for Pre-Order

{% else %}
  

Out of Stock

{% endif %}

If my reply is helpful, kindly click like and mark it as an accepted solution.
Thanks!

Hey thanks for your help

But I don’t think this code fully solves the problem I’m having

Please find the current code below

{%- when 'inventory' -%}
              

                {%- if product.selected_or_first_available_variant.inventory_management == 'shopify' -%}
                  {%- if product.selected_or_first_available_variant.inventory_quantity > 0 -%}
                    {%- if product.selected_or_first_available_variant.inventory_quantity <= block.settings.inventory_threshold -%}
                      
                      {%- if block.settings.show_inventory_quantity -%}
                        {{- 'products.product.inventory_low_stock_show_count' | t: quantity: product.selected_or_first_available_variant.inventory_quantity -}}
                      {%- else -%}
                        {{- 'products.product.inventory_low_stock' | t -}}
                      {%- endif -%}
                    {%- else -%}
                      
                      {%- if block.settings.show_inventory_quantity -%}
                        {{- 'products.product.inventory_in_stock_show_count' | t: quantity: product.selected_or_first_available_variant.inventory_quantity -}}
                      {%- else -%}
                          {{- 'products.product.inventory_in_stock' | t -}}
                      {%- endif -%}
                    {%- endif -%}
                  {%- else -%}
                    {%- if product.selected_or_first_available_variant.inventory_policy == 'continue' -%}
                      
                      {{- 'products.product.inventory_out_of_stock_continue_selling' | t -}}
                    {%- else -%}
                      
                      {{- 'products.product.inventory_out_of_stock' | t -}}
                    {%- endif -%}
                  {%- endif -%}
                {%- endif -%}