Skip Navigation

[Resolved] How to Display Conditional message based User field empty

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

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 support ticket is created 3 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 10 replies, has 3 voices.

Last updated by manishB-2 3 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#2049219

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.

#2049221

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]

#2049665

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]
#2049667

Unfortunately, Its not working.

#2049669

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.

#2049677

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]
#2050705

Its still the same issue. Not getting any result

#2051091

Shane
Supporter

Languages: English (English )

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

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.

#2052133

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.

#2056713
without-phone.png
with-phone.png
profile-incomplete.png
profile-complete.png
editor.png

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.

#2056779

My issue is resolved now. Thank you!