Navigation überspringen

[Gelöst] How to use _stock field in a conditional output

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

I want to display the stock level with different colors depending of the stock value.

Solution:

You can get the the custom field "_stock" value with Views shortcode:
[wpv-post-field name="_stock"]

Then use it in [wpv-conditional] shortcode, like this:

[wpv-conditional if="( '[wpv-post-field name="_stock"]' gt '3' )"]
 ... stock is greater than 3 ... 
[/wpv-conditional]

Relevant Documentation:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field

This support ticket is created vor 6 Jahren, 2 Monaten. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Pat vor 6 Jahren, 2 Monaten.

Assistiert von: Luo Yang.

Author
Artikel
#1147049

Pat

Hello,

I'm trying to create a condition in a product content template and have an issue.

I want to display the stock level with different colors depending of the stock value.
So, I have integrated _stock in the Types custom fields management. Then, I have added _stock in the additional function for contitional output (in the Toolset parameters).

Now, if I place the shortcode [wpv-post-field name='_stock'] inside the content template, everything works fine, but if I try to use it inside a conditional output like :

[wpv-conditional if="( _stock() gt '3' )"]<table class="fondvert" style="width:100%;font-weight:bold;text-align:center;color:white;font-size:1.2em;"><tbody><tr><td>Il reste [wpv-post-field name='_stock'] places pour ce stage</td></tr></tbody></table>[/wpv-conditional]

this is not working (nothing is displayed).

Did I miss something?
Regards
Pat

#1147075

Dear Pat,

You can get the the custom field "_stock" value with Views shortcode:
[wpv-post-field name="_stock"]

Then use it in [wpv-conditional] shortcode, like this:

[wpv-conditional if="( '[wpv-post-field name="_stock"]' gt '3' )"]
 ... stock is greater than 3 ... 
[/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field

#1147910

Pat

Hi Luoy,
Perfect
Thanks
Pat