Skip to product information
1 of 1
Published:2026.08.19

Auto-record stock status to a metafield with Shopify Flow and use it as a Search & Discovery filter

Auto-record stock status to a metafield with Shopify Flow and use it as a Search & Discovery filter

Applications

  • 在庫管理
  • Shopify Flow管理・編集
View full details

The built-in "Availability" filter in Search & Discovery looks at inventory per variant. So a product shows up under "Out of stock" as soon as a single variant runs out — a shirt whose only sold-out size is S ends up listed next to genuinely sold-out products.

The URL parameter explains why. The built-in filter is filter.v.availability, and the filter.v. prefix means the scope is the variant, not the product. 0 means out-of-stock variants and 1 means in-stock variants, so a product with a mix of both matches "In stock" and "Out of stock" at the same time.

There is no built-in way to ask "is every variant sold out?" at the product level. So you keep your own product metafield for stock status, let Shopify Flow maintain it, and filter on it as a filter.p. (product-level) filter. It reads "Out of stock" only once every variant has become unavailable, and returns to "In stock" as soon as any variant has stock again.

Result: filtering products by stock status


What this setup involves

◆Create a product metafield that holds the stock status
◆Build a Flow that watches inventory changes and rewrites that value
◆Add a Search & Discovery filter whose source is that metafield

Because the logic lives in Flow, you can move away from "only when everything is sold out" to whatever rule you need. You also control the label, and you can add extra states such as "Backorder" or "Pre-order" later. The built-in filter allows none of that.


[Step 1] Create the stock status product metafield

◆Shopify admin → Settings → Custom data → Products → Add definition
◆Name it "Stock status" and pick the type "Select list (single line text)"
◆Register "In stock" and "Out of stock" as the validation choices
◆Turn on "Storefront API access" under Options

Step 1: the product metafield definition

If Storefront API access stays off, the metafield will not appear as a filter source in Step 3. It is the easiest part to miss, so it is worth confirming up front.


[Step 2] Build the Flow that watches inventory

◆Shopify admin → Apps → Flow → Create workflow
◆Trigger: Product variant inventory quantity changed
◆Condition: pick product / variants, set the list operator to "All of", and check that availableForSale is False
◆On the True branch, add "Update product metafield" and set Stock status to "Out of stock"
◆On the False branch, add the same action and set it to "In stock"

Step 2: the Flow condition and its two branches

The operator list still contains "All of … or list is empty (deprecated)". It treats an empty list differently, so pick the one without the (deprecated) suffix. The .flow file shown after purchase lets you import this workflow as it is.


[Step 3] Add the filter in Search & Discovery

◆Shopify admin → Apps → Search & Discovery → Filters → Add filter
◆Choose "Product metafield: Stock status" as the source
◆Type the label you want customers to see
◆Save

Step 3: the Search & Discovery filter settings

You can leave the built-in Availability filter in place, or drop it and keep only this one if having both is confusing.


Why totalInventory must not decide stock status

It is tempting to use product.totalInventory in the Flow condition, but it excludes variants whose inventory is not tracked. Such a variant can be bought without limit, yet it contributes zero to the total. Deciding "out of stock when the total is zero or less" therefore flags products that customers can still buy.

How totalInventory and availableForSale differ

availableForSale is Shopify's final answer to whether a variant can be bought right now. It already accounts for inventory tracking, the continue-selling-when-out-of-stock setting, and the quantity, so it is the only value you need to read.


Things to watch in day-to-day use

◆Flow only runs at the moment inventory changes. Existing products get no value, so you need one bulk backfill at the start
◆A filter value with zero matching products disappears from the storefront filters
◆Search & Discovery allows up to 25 filters per store