Skip Navigation

[Resolved] Conditional Breaking with WooCommerce Stock Level

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Christian Cox 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1123847

Lee

Hi,

I have a condition set up based on the WooCommerce stock level of products.
When a product is in stock (gte 1), the 'Add to Basket' button shows.
When a product is out of stock (eq 0) a 'Join Waiting List' button shows instead.

The condition is working fine until the stock level changes from 1 to 0.
When this happens nothing displays, and it just seems to break.
If you open up the product and re-save it, everything works fine again.

You can see examples below of the issue.

The list has random products when you scroll down that don't display a button: hidden link

If you click into one of these products the template is empty: hidden link

This is what should display: haunted-houses-co-uk.stackstaging.com/event/ford-green-hall-fri-21st-dec-2018/

Any thoughts?

Thanks
James

#1124018

Hi, it appears that the Upcoming Events page is restricted because I'm shown a 404 Page not found error. I'm also not able to see the actual code in your conditional, so I can't validate the syntax. If you're able to provide login credentials in the private reply fields here, I will be glad to take a closer look.

#1125520

Hi, I can see that things are breaking down here because the wpv-post-field shortcode for "_stock" doesn't return anything on the blank-looking Product pages. No zero is returned, and the conditionals are incomplete because they do not allow for a null value, which is apparently possible somehow. Conditionals that test a null value are tricky, so I usually add a character to the test string and test the result. The result should be the same as the extra character. Like this:

[wpv-conditional if="( ('a[wpv-post-field name="_stock"]' eq 'a') OR ('[wpv-post-field name="_stock"]' eq '0'))"]

I would update all the conditionals that test if the _stock value is eq '0' using the code above as a guide. Then let me know if the problem is not fully resolved and I can take a closer look.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.