NO BUG: Woo_product_stock variable does not work with conditions

Bricks Version: 1.5.7
Browser: Chromium 107.0.5304.110
OS: macOS

I’m facing an issue with woo_product_stock variable used as an element display condition :frowning:

Here’s the context :

  • I have a template to work with my woocommerce products.
  • I am working with variable products.
  • I want to hide a container with product price, stock and add to cart element if my product is out of stock and display a disclaimer text instead.

For that, i created 2 containers :

  • Container A, with 3 elements : product price, product stock and add to cart.
  • Container B, with a simple text element (to say that the product is out of stock without showing other unneeded informations).

I set the following display conditions:

  • container A : woo_product_stock > 0
  • container B : woo_product_stock == 0

After some tests, only container A is displayed even if the product stock is 0. It seems that the condition is not triggered.

Hi Quentin,
If the product stock quantity is “0”, the {woo_product_stock} dynamic data tag shows “Out of stock” instead of “0”, so comparing it against “0” doesn’t work.

You can use “Contains” » “Out of stock” or “Does not contain” » “Out of stock”, which seems to work fine in my tests.

Best regards,
timmse

1 Like

Stumbled upon this old topic from search. Thank you for the fix. For me, 1:1 this didn’t work, but using just the word “Out” in place of “Out of stock”, works!

Is there a way to show an element if the stock level is a certain number. I was hoping something like this works. Please help

Hey,

something like this should work:

Note that I added :value at the end, so Dynamic data looks like this: {woo_product_stock:value}, then in the last field, just compare to whatever number you want.

In my case, it will show the element if the stock is equal to 1.

Additionally, here you can see a list of available WooCommerce dynamic data and modifiers: WooCommerce Builder – Bricks Academy

That

1 Like

Hi,

{woo_product_stock:value} works for both simple and variable products.
But I can never work with {woo_product_stock_status}. While it should support “Out of stock” or “In stock” values. But it still doesn’t work. What is actually the use of {woo_product_stock_status}?

1 Like

As per documentation, {woo_product_stock_status} will output instock, outofstock, or onbackorder, so if you compare with this values, it should work. :slight_smile:

2 Likes

Thank you so much! I’ll try that :raised_hands:t4:

1 Like