Home › Toolset Professional Support › [Resolved] How to Display Conditional message based User field empty
Problem: I would like to display some content conditionally based on whether or not the User's WooCommerce 'billing_phone' field has a value.
Solution: In the legacy editor, you can use the following syntax to test the value of a User's WooCommerce field:
[wpv-conditional if="( '[wpv-user field="billing_phone"]' eq '' )"] empty billing phone [/wpv-conditional] [wpv-conditional if="( '[wpv-user field="billing_phone"]' ne '' )"] non-empty billing phone [/wpv-conditional]
100% of people find this useful.
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 10 replies, has 3 voices.
Last updated by manishB-2 3 years, 6 months ago.
Assisted by: Christian Cox.
Hi Guys
I need help to display two different conditional messages based on a current user's field value. For example user profile field "billing_phone" is empty then a custom message should display in a page. and if "billing_phone" is not empty then a different message should display.
I have added the below code but its not working.
[wpv-conditional if="( '[wpv-user field='billing_phone' id='[wpv-current-user info="id"]']' ne '' )"] <div class="pro-okay"> <h4>Good News! Your Profile is completed. You can still update your profile. <a href="/edit-profile">Click Here</a></h4> </div> [/wpv-conditional] [wpv-conditional if="( '[wpv-user field='billing_phone' id='[wpv-current-user info="id"]']' eq '' )"] <div class="pro-not"> <h4>[wpv-current-user info="firstname"]! Your Profile is not complete. Please fill all your profile details. <a href="/edit-profile">Click Here</a></h4> </div> [/wpv-conditional]
Please help me fix this code to make it.
I tried this code as well. But nothing is working
[wpv-conditional if="( NOT(empty($([wpv-current-user info="billing_phone"]))))"] <div class="pro-okay"> <h4>Good News! Your Profile is completed. You can still update your profile. <a href="/edit-profile">Click Here</a></h4> </div> [/wpv-conditional] [wpv-conditional if="( (empty($([wpv-current-user info="billing_phone"]))))"]<div class="pro-not"> <h4>[wpv-current-user info="firstname"]! Your Profile is not complete. Please fill all your profile details. <a href="/edit-profile">Click Here</a></h4> </div> [/wpv-conditional]
Hello, please try this alternate syntax for testing User field values:
[wpv-conditional if="( '[types usermeta="billing_phone" current_user="true"][/types]' ne '' )"] <div class="pro-okay"> <h4>Good News! Your Profile is completed. You can still update your profile. <a href="/edit-profile">Click Here</a></h4> </div> [/wpv-conditional] [wpv-conditional if="( '[types usermeta="billing_phone" current_user="true"][/types]' eq '' )"] <h4>[wpv-current-user info="firstname"]! Your Profile is not complete. Please fill all your profile details. <a href="/edit-profile">Click Here</a></h4> [/wpv-conditional]
Unfortunately, Its not working.
billing_phone is a Woocommerce user field. So I just wanna confirm if there will be any additional function or setting has to be added or modified.
Okay I see, I thought you were testing the value of a Types field. To test a WC field like this, the following syntax works in my local test for the current logged-in User:
[wpv-conditional if="( '[wpv-user field="billing_phone"]' eq '' )"] empty billing phone [/wpv-conditional] [wpv-conditional if="( '[wpv-user field="billing_phone"]' ne '' )"] non-empty billing phone [/wpv-conditional]
Its still the same issue. Not getting any result
Hello,
Christian is currently on a public holiday today but he will be back tomorrow to continue assisting you with this one.
Thank you for the patience and understanding.
Okay it works in my local test so there must be something else going on. May I log in and see how this is implemented on your site? Please provide admin login credentials in the private fields here. Let me know where I can find the conditional in wp-admin, and where it should appear on the front-end of the site.
It seems to be working correctly for me. I edited the Account page and added the conditional code in a text element. I see the information displayed now on the account page depending on whether I have information in my User account's billing phone area. Can you check? Screenshots attached here.
My issue is resolved now. Thank you!