I have a custom User field "user-department" and a custom field "asset-department" added to the WooCommerce Product CPT. When listing Products using a Content Template, I want to use a Conditional to only display certain Product content when the product's 'asset-department' is the same as the current user's 'user-department'. I can't seem to figure out how to configure this - can you help?
Hello. Thank you for contacting the Toolset support.
Can you please try to use the conditional statement as given under:
- For classic content template you can add it directly to template editor
- For block based content template you should try to add "Fields and Text" block or "Shortcodes" block and add the conditional shortcode within it as follows
[wpv-conditional if="( '[types usermeta='user-department' user_current='true' output='raw'][/types]' eq '[types field='asset-department' output='raw'][/types]' )"]
Your content goes here
[/wpv-conditional]
Hello and thank you for your help, Minesh. However, I'm not sure how to proceed with the solution you provide above. I am using a block-based template, and the content of the Conditional is a "Fields and Text" block which contains the following:
[toolset-edit-post-link content_template_slug='edit-asset-admin' target='self']Edit This Asset[/toolset-edit-post-link]
. This works in another Content Template that doesn't require a Conditional.
In the Content Template that needs the Conditional, I tried replacing the "Fields and Text" block with a "Shortcode" block and putting everything in it:
but that doesn't work at all.
I'm happy to give you access so you can look at this situation directly. This is a development project and it's fully backed up.
Sure. Can you please share problem URL and admin access details and what content/fields you want to display when condition is satisfied.
Also share frontend user access details (if required) for testing where for that user you setup the user field "user-department".
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
The condition is not working because as you can see with both the custom field groups where you configure your custom field:
Asset Department field:
- versteckter Link
User Department field:
- versteckter Link
If you notice the value for the options setup with both the fields are different.
For field User Department the option "Art Dep" value setup as "Art Dep" and with the field "Asset Department" the option "Art Dep" value setup as "art-dep" so it does not match.
To overcome the option value mismatch I've added the following code to "Custom Code" section offered by Toolset with the code snippet namely "toolset-custom-code":
add_shortcode( 'get_user_field_user_dept', 'func_get_user_field_user_dept' );
function func_get_user_field_user_dept() {
global $current_user;
$value = get_user_meta($current_user->ID,'wpcf-user-department',true);
$value = str_replace(" ","-",strtolower($value));
return $value;
}