SOLVED: Dynamic data: {woo_product_stock} issue Woocommerce products on back-order stock QTY display as positive integer

@devs - First of all thanks for awesome product - bricks rocks.

Issue:
Using Woocommerce dynamic data {woo_product_stock:value} to display stock QTY - works as it should, BUT when stock is on “back order” ( where Woocommerce sees it as a negative number) it still displays as positive number.

or as @MatejMohar eloquently put it to me in the discord: “As Bricks always returns absolute value, that’s why instead of -20 it returns 20. That way you can’t even have conditions to check if value is negative”

Steps to recreate:

  • On fresh WP / Bricks / WooCommerce install set a product to have stock of 5
  • set “allow back order” in products settings
  • go to product, order 25 items, and checkout
  • in back-end displays -20 products in stock - which is correct
  • Front end displays 20 - which is incorrect


Hey Pieter,

thanks a lot for your report.

As I’m not an e-commerce or WooCommerce expert I’m hearing of this backorder term for the first time. :smiley: But yeah. In this case this sounds like a bug to me. However, I will leave this report on WAIT for now and get some feedback internally.

Best,

André

1 Like

Thanks so much!

Same this side. I have not worked with WOO too much - we discovered it when clients demanded stock we don’t have :smiley:

I believe the absint() might be the issue there. as it forces the number positive (I think)

The other big question it what should it return when it is negative - maybe it should be something that can be fed into the dynamic data term something like

  • {woo_product_stock:value:0} returns a 0 for negative stock value
  • {woo_product_stock:value:No stock }" returns a “No stock” for negative stock value
  • {woo_product_stock:value:On back order }" returns a “On back order” for negative stock value

Just a thought :slight_smile:

Hey Pieter,

we agree that the absint solution isn’t ideal and will see how we can improve this.

Best,

André

Awesome Thanks!

Shout out to @matejmohar for pointing to the issue! :slight_smile:

1 Like

Hi Pieter,
We’ve fixed this issue in Bricks 1.9.1/1.9.1.1, now available as a one-click update in your WordPress Dashboard.

Please let us know if you are still experiencing issues.

Best regards,
timmse

Great News!
Awesome! Thanks for the effort!
Looking forward test it!