Adding Metafields to Disable Add to Cart for OOS Products
Last updated
Was this helpful?
Last updated
Was this helpful?
This guide outlines how to replicate "Out of Stock" behavior on product display pages (PDPs) while still allowing subscription orders to be processed.
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.
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.
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 Stock
to true.
Modify Your Theme Code
Go to Online Store > Themes > Edit Code
Find your product.liquid
, main-product.liquid
, or product.json
template, 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 1
Example 2 (in product-form.liquid
)