Removes out-of-stock products from a configured manual collection via collectionRemoveProducts, never deleting or unpublishing them.
async def run(ctx): collection = ctx.params["collection_id"] stale = [] for product in await ctx.collections.products(collection):
How do you remove out-of-stock products from a Shopify collection automatically?
To remove out-of-stock products from a Shopify collection automatically, this template scans a configured manual collection and removes products whose total inventory has hit zero. It removes them from that collection only: nothing gets unpublished, drafted or deleted, and the products stay live on their own pages and in every other collection. Point it at the homepage edit, the campaign collection, the lookbook, or any curated set that a merchandiser builds by hand.
Manual collections are curated once, which means sold-out items sit in your homepage edit until someone notices the greyed-out card. Smart collections can filter by stock; manual ones cannot, and that gap is exactly where this template runs. Each pass lists which products it would remove from which collection, so the merchandiser signs off on the cut before shoppers see holes or, worse, click into sold-out products.
Last updated August 24, 2026
If you run a sharper version of this template, or something it inspired, send it in. We review every application and publish the good ones, credited to you or your agency.
AI writes real Python or TypeScript, a dry run rehearses it, you approve, it deploys.
Free plan · no card · 🇪🇺 EU data residency