CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Is In Stock

is_in_stock checks whether a product is currently available and returns a boolean-style result. Use it to show an In stock/Sold out message or decide whether to render an Add to Cart button.

See also:

Parameters

entry_id

Required numeric product entry ID.

If entry_id is missing or not numeric, the tag returns false-like output.

entry_id="123"

Behavior and Constraints

  1. This is an immediate-execution single tag.
  2. Tag loads product data using ee()->cartthrob->get_product(entry_id).
  3. If product cannot be loaded, result is false-like output.
  4. If product is loaded, the tag checks aggregate product inventory.
  5. For a product with an ordinary mapped inventory field, a value greater than zero is in stock. Zero or a negative value is out of stock.
  6. A blank ordinary inventory value, or no mapped inventory field, represents unlimited inventory and returns in stock.
  7. For a product using modifier inventory, the aggregate check returns in stock when at least one valid option has positive or unlimited inventory. An entry with no modifier rows is unlimited and returns in stock. It returns out of stock only when its existing options are explicitly unavailable.
  8. This tag does not accept item-option parameters. It cannot answer whether one selected size, color, SKU, or configuration is in stock. Use the {inventory} custom column inside the item_options option loop to display availability for individual choices.
  9. Inventory resolution still runs through the product inventory logic/hook path, including inventory calculation hooks.
  10. The result is a storefront display aid. add_to_cart_form, cart updates, and checkout perform their own server-side inventory validation in case stock changes after the page is rendered.

CartThrob uses the product channel’s single Inventory mapping for this check. It does not combine an ordinary inventory field with one or more modifier fields. See Edit Product Channel for the mapping rules and Price Modifiers Configurator for combination/SKU inventory.

Examples

Conditional stock message:

{if '{exp:cartthrob:is_in_stock entry_id="123"}'}
    In Stock
{if:else}
    Out of Stock
{/if}

Use with channel entry ID:

{if '{exp:cartthrob:is_in_stock entry_id="{entry_id}"}'}
    <button type="submit">Add to Cart</button>
{if:else}
    <span>Sold Out</span>
{/if}

Stock-aware add-to-cart form:

{exp:cartthrob:add_to_cart_form
    entry_id="{entry_id}"
    return="store/cart"
    error_handling="inline"}

    {if '{exp:cartthrob:is_in_stock entry_id="{entry_id}"}'}
        <button type="submit">Add to Cart</button>
    {if:else}
        <p>Out of stock</p>
    {/if}

    {if errors_exist}
        {errors}<p class="error">{error}</p>{/errors}
    {/if}
{/exp:cartthrob:add_to_cart_form}

Do not omit the error output. A product can sell out after the page is rendered but before the customer submits the form.