Skip Navigation

[Resolved] WooCommerce Stock Level Condition

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to display a conditional text based on the woocommerce stock level.

Solution:

This can be done by doing this.

[wpv-conditional if="( [wpv-post-field name='_stock'] lt '1' )"] CONTENT [/wpv-conditional]

The code above will display "CONTENT" if the stock level is less than 1.

For greater than you can use "gt" instead of the "lt" that is used in the example.

This support ticket is created 5 years, 8 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Lee 5 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#1088471

Lee

Hi,

I am trying to create a conditional based on a WooCommerce products stock level.
The shortcode "[wpv-post-field name='_stock']" pulls through the stock quantity, but I can't get the shortcode to work as part of a conditional?

So for instance if I wanted to show "CONTENT" when the stock level is <1, I have tried the following...
[wpv-conditional if="( $(wpv-post-field name='_stock) lt '1' )"] CONTENT [/wpv-conditional]

Thanks
James

#1088505

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Lee,

Thank you for contacting our support forum.

You actually need to write it like this.
[wpv-conditional if="( [wpv-post-field name='_stock'] lt '1' )"] CONTENT [/wpv-conditional]

Please try this and let me know.

Thanks,
Shane

#1089276

Lee

Great thanks Shane, worked a treat!

Cheers
James

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