Remove Product from Specific Sales Channel when under Specific Inventory Amount for Variant

Topic summary

  • Goal: Automatically remove a product from the Online Store sales channel when all its variants are under a custom inventory threshold, to prevent ads from showing items that are effectively unavailable online.

  • Current setup: A metafield-based limit marks variants below the threshold as “out of stock” online while brick-and-mortar stores can still sell remaining stock.

  • Constraint: Liquid (theme templating) can hide/disable variants in the storefront but cannot change admin settings or unpublish items from a sales channel.

  • Recommended approach: Use the Shopify Admin GraphQL API (Admin API). Periodically check inventory via the inventoryLevel query and, when conditions are met (all variants below threshold), call the publishableUnpublish mutation to remove from the Online Store sales channel. Implement this logic in a custom app.

  • Status: The suggested API-based solution will be tried; no final confirmation or code shared yet.

Summarized with AI on December 21. AI used: gpt-5.

Hello! So, currently, we have an inventory limit that makes it so we don’t oversell products in our brick and mortar stores when the products goes out of stock online. The way it works is that it will display “out of stock” on the online for product variants under a specific number of inventory we define through metafields, but the brick and mortar stores can still deliver their remaining stock.

Now for the issue I am trying to solve. We are having ads show out of stock online product because they don’t identify when the product variants are all under the inventory limit. Is there a way through liquid code to access admin controls to ‘remove from online store’ through store channels when ALL variants for a product fall under the inventory limit threshold?

Let me know if I can clarify or offer our current code base for the inventory limit! Cheers!

Hi ShopMatt,

So you could use Liquid to make a product/variant show up as “unavailable” when inventory falls below a certain limit, but this won’t communicate anything back to the admin. A Liquid customisation will just prevent a customer from selecting that variant but won’t unpublish it from the online store sales channel.

To automate this process you’d likely need to use Admin API the publishableUnpublish mutation which would be triggered by conditions/business logic you set up in a custom app. You could use the inventoryLevel query to periodically check inventory levels and when the level falls under the threshold the publishableUnpublish mutation would be used to unpublish the variant from the Online Store channel.

Thanks, Liam! I’ll give that a try!