I'm having a problem with the inventory field in a product in cartthrob. For my product, there are color variations for each product and the inventory is assigned accordingly.

When displaying the products on the "add to cart" page, the cartthrob options tag will check for inventory and only display the color if it's in stock.

The problem is that if the inventory reaches 0 on both color variations, the options will still show the product (with an empty select tag).

How can I have this product not show up in my template logic if there is no inventory left for any of the variations?

{if inventory !=0 }

<option name="item_options[product_color]" value="{option_value}">{option_name}</option>


enter image description here

Ideally, if all inventory is at 0 in these product fields, I'd like a message to show the product is out of stock and not allow the add to cart functionality.

  • We're looking to do the exact same check for the exact same issue. We looked through the CartThrob docs and haven't come across anything useful. I have a feeling a custom plugin might be needed. Commented Dec 10, 2013 at 17:10
  • Hmm, just thinking off the top of my head: I know you can setup PM fields as a matrix field. Not sure if that's the most efficient with your current case, but ultimately with matrix you could just run a search conditional on the matrix column. Food for thought
    – Siebird
    Commented Dec 10, 2013 at 17:24
  • Just an idea which, admittedly, I haven't fully thought out: Maybe you could write an extension which, once the field hits zero, it removes the zero so it's just a blank field. According to this it will show if blank but not if zero and hopefully at that point you could get the conditional {if inventory ==""} to work.
    – Natetronn
    Commented Dec 10, 2013 at 18:18
  • I will follow up with this shortly and explain how i worked around this
    – Chris M
    Commented Dec 10, 2013 at 19:05
  • In our case, we ended up using the cartthrob_product_reduce_inventory_method hook to check if all the item options have run out when someone places their order. If there is no inventory for the item at all, we close the entry. Commented Dec 10, 2013 at 21:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.