Only show In Stock availability based on one location

I have products in my warehouse but most products are dropshipped. I have my products.product.inventory_in_stock_show_count set to “In Stock and Ready to Ship” and products.product.inventory_in_stock set to “Usually Ships in 7 Days”, and all products are set to Continue Selling When Out Of Stock which worked perfectly.
In order to give better shipping estimates, I added 150 or so locations with inventory set to 99,999 for the dropshipped items, but now everything says “In Stock and Ready to Ship” so I am trying to set it so it only checks if the warehouse location has inventory. Unfortunately I can’t get the If/Else statements to work, it seems to think that if a product is available anywhere, then it is available at my warehouse. Any ideas? I’ve tried replacing location.name with location.id but that didn’t make a difference.

{%- if block.settings.show_inventory_quantity -%}
{% for availability in product.selected_or_first_available_variant.store_availabilities %}
{%- if availability.location.name == ‘Warehouse’ and availability.available -%}
{{- ‘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 %}
{% endfor %}
{%- else -%}
{{- ‘products.product.inventory_in_stock’ | t -}}
{%- endif -%}

hii @SP_Young

The issue is that you’re looping through all store_availabilities so if anylocation is available your loop will hit that and output the In Stock message.

Instead of printing inside the loop, first check specifically whether your Warehouse location has stock then print once.

Try this approach

{%- assign warehouse_available = false -%}

{%- for availability in product.selected_or_first_available_variant.store_availabilities -%}
{%- if availability.location.name == Warehouse’ and availability.available -%}
{%- assign warehouse_available = true -%}
{%- endif -%}
{%- endfor -%}

{%- if warehouse_available -%}
{{ '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 -%}

Don’t output inside the loop
Set a flag warehouse_available
Output once after the loop

I think I see what you mean, my code should give an inventory status for every location, but your code gives me the same result unfortunately. Everything is Ready to Ship as long as there is a location with inventory, regardless of which location it is.

Just to confirm – you know that store_availability is for local pickup only?
It’s not the same as inventory levels?

Note
The store_availability object is defined only if one or more locations has local pickup enabled.

For anyone coming here in the future, I ended up having to set the flag based on a custom “In stock? T/F” metafield within each item.