Skip to content

Instantly share code, notes, and snippets.

@jonathanmoore
Created February 12, 2024 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanmoore/626ecc74561b218331c0389969dc80c7 to your computer and use it in GitHub Desktop.
Save jonathanmoore/626ecc74561b218331c0389969dc80c7 to your computer and use it in GitHub Desktop.
{% liquid
assign low_stock_threshold = 5
assign selling_fast_threshold = 12
assign low_stock_status = "Low stock"
assign selling_fast_status = "Selling fast"
assign in_stock_status = "In stock"
assign low_stock_color = "#FFD700"
assign selling_fast_color = "#008000"
assign in_stock_color = "#808080"
assign stock_status = in_stock_status
assign stock_color = in_stock_color
if product.selected_variant.inventory_management and product.selected_variant.inventory_quantity > 0
if product.selected_variant.inventory_quantity < low_stock_threshold
assign stock_status = low_stock_status
assign stock_color = low_stock_color
elsif product.selected_variant.inventory_quantity <= selling_fast_threshold
assign stock_status = selling_fast_status
assign stock_color = selling_fast_color
endif
endif
%}
<div class="product__inventory rte rte-sm">
{% if product.selected_variant.inventory_quantity > 0 and product.selected_variant.available %}
<span style="height: 10px; width: 10px; background-color: {{ stock_color }}; border-radius: 50%; display: inline-block; margin-right: 5px;"></span>
{{ stock_status }}: {{ product.selected_variant.inventory_quantity }} available
{% endif %}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment