Adding Metafields to Disable Add to Cart for OOS Products
Objective
This guide outlines how to replicate "Out of Stock" behavior on product display pages (PDPs) while still allowing subscription orders to be processed.
Background
Currently, for subscriptions to process orders that include products with negative inventory, the "Continue selling when out of stock" option must be enabled. However, enabling this setting also allows new, one-time purchases of these out-of-stock items, which may result in overselling.
Purpose
To address this, the following guide provides a method to simulate an "Out of Stock" state for one-time purchases—restricting new customers from buying unavailable items—while still permitting existing, recurring subscription orders to process as usual.
How To Implement
Create the Metafield
Go to Settings > Custom data > Products in Shopify admin.

Add a new definition
Name: Force Out of Stock (feel free to adjust as needed)
Key:
force_out_of_stock(this will autopopulate from the name)Type: Boolean (True/False)

Set the Metafield for Specific Products
Navigate to a product that you want to “set out of stock” visually on the frontend.
Scroll to the metafields section at the bottom.
Set
Force Out of Stockto true.

Modify Your Theme Code
Go to Online Store > Themes > Edit Code
Find your
product.liquid,main-product.liquid, orproduct.jsontemplate, depending on your theme.Locate your purchase button (i.e. add to cart button or buy button).
Modify the display of the purchase button based on the Force Out of Stock metafield.
When this metafield is enabled, a disabled version of the "Buy" button should be shown to simulate an out-of-stock state.
If the metafield is not enabled, the standard "Buy" button should be displayed as usual.
Example Templates
Example 1
Example 2 (in product-form.liquid)
Last updated
Was this helpful?

