Skip Navigation

[Resolved] data-dependent conditional field display in admin

This support ticket is created 4 years, 1 month 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
- 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)

Tagged: 

This topic contains 4 replies, has 3 voices.

Last updated by charleneK 4 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1833531

Tell us what you are trying to do?

I'm attempting to conditionally display a custom field group in a woo commerce order.

Is there any documentation that you are following?

https://toolset.com/course-lesson/custom-fields-conditional-display/

Is there a similar example that we can see?

No

What is the link to your site?

hidden link

I'm attempting to use the data-dependent (advanced text settings) to conditionally display a types group in a woocommerce order post, but i'm not having much luck. using:

NOT (empty($(my_custom_field)))

Basically, I have a simple custom text field created by woo-commerce, when a certain product ordered. meaning if a user orders a certain type of product, then this custom field will be part of the order meta fields.

I also have a custom field group called "Options" (created in toolset types) which I only want to display if the woocommerce custom field exists in the order. trying to conditionally display with data-dependent filter.

I don't seem to be having much luck with
NOT (empty($(my_custom_field)))

also tried
!empty($(my custom_field))

not sure what to try.....

hope that makes sense. thanks much for any help++

#1833703

It's looking like this might only work with toolset custom fields? Possible to make it work with non-toolset types fields?

#1834097

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You are right, the conditional display only works with Toolset fields, not those of 3rd parties.

There isn't any way to make it work with 3rd party fields, you will need a custom solution that doesn't use the Toolset code.

You can add your own JS to the page by enqueuing a script on the relevant admin pages using the admin_enqueue_scripts hook (https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/).

You'll need to use your browser dev tools to inspect the markup of the admin page in question and identify a selector for the part you want to hide as well as a selector for the input that will determine the conditional display.

Your code will check the value of the input and set the visibility of the target section accordingly, and you'll want to add it via the load and change event listeners, so that the visibility is correct when the page first loads and updates as needed.

If using jQuery the following should help:

hidden link
hidden link
hidden link
hidden link

#1835093

Hello,

Please let me know if you need more assistance for it. thanks

#1835115

My issue is resolved now. Thank you!

I managed a solution by creating a script for my functions.php that checks the field for its value, and then removes the meta fields from the output.