Skip Navigation

[Resolved] Some help on 'if' shortcode

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

This topic contains 3 replies, has 2 voices.

Last updated by willem-siebeS 8 years, 7 months ago.

Assigned support staff: Paweł Pela.



I'm using views to create my woocommerce archive pages and display the products in there with a content template.
Now, some of the products I'm showing to the public, have NO RETAILPRICE set, because these products are only to be sold to wholesale customers.
I want to present the non logged in users and the normal customers with a extra message that these products are wholesale only.

The first part is easy:

[wpv-if arg1="_price" evaluate="empty($arg1)"]No url given[/wpv-if]

Wholesale only products don't have a normal retailprice, so with above code I can show a warning on the products to check is the _price field is empty.

Only problem: when a wholesale customer (role = wholesale) is logged in, he/she also sees this message. I don't want that.

In my functions.php I have:

function appthemes_check_user_role( $role, $user_id = null ) {

if ( is_numeric( $user_id ) )
$user = get_userdata( $user_id );
$user = wp_get_current_user();

if ( empty( $user ) )
return false;

return in_array( $role, (array) $user->roles );

When I use this in my own functions.php to hide content when a user is logged in as 'wholesale customer', this is working.

I now trie to use it with TVC toolset like this:

[wpv-if evaluate="appthemes_check_user_role( 'customer') = 'false'"]Tagged Test[/wpv-if]


[wpv-if evaluate="appthemes_check_user_role( 'customer') = 'true'"]Tagged Test[/wpv-if]


[wpv-if evaluate="appthemes_check_user_role( 'customer')"]Tagged Test[/wpv-if]

Nothing working. What am I doing wrong?

And how to merge both, so that is it showing the message when _price field is empty, except when the customer is logged in als 'wholesale'...

Kind regards,



Dear willem-siebeS,

The problem with your function is that it returns not a string, but bool true or false and in your wpv-if you try to compare it against a string value. Make your function return 0 or 1 instead and it will work.

As for the merging, here's how you can do it:

[wpv-if arg1="_price" evaluate="appthemes_check_user_role( 'customer') = 1 AND empty($arg1)"]Tagged Test[/wpv-if]

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.



Hi, your explenation with my earlier mentioned URL to other help topic made it work:

[wpv-if arg1="_price" evaluate="empty($arg1) AND '[wpv-post-get-wp-user-role]' != 'ignite_level_5367f4bc4171a'"]Dit product verkopen wij alleen aan professionals[/wpv-if]

Thanks a lot.