Skip Navigation

[Resolved] Effectively Utilizing Conditional Logic with Multiple Arguments

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Minesh 9 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2686010
Screenshot 2024-03-01 at 12-26-56 Edit Content Template “Single Product Layout” ‹ Triple E Apparel — WordPress.png

I'm trying to display a container based on multiple different conditions using Toolset's Conditional Logic system, but it doesn't appear to be working in the manner I expected it to. Here are the conditional arguments I'm trying to work with.

I want the container to be displayed if the current post fulfills any one of these conditions. If none of these conditions are met, then the container should not be displayed.

  • If the post body is populated OR
  • If the WooCommerce product is a Variable Product, determined by the product_type taxonomy with the value "variable" OR
  • If the [wpv-view name="style-size-chart-content"] view does not output an empty value

This is how I currently have my conditional arguments marked up:

[wpv-conditional if="( wpv_conditional_post_has_content() eq '1' ) OR ( CONTAINS(#(product_type),'variable') ) OR ( '[wpv-view name='style-size-chart-content']' ne '' )"] [...] [/wpv-conditional]

I tried changing the OR condition to AND, which displays the container if all of those conditions are met and hides the container if they aren't all met, which is not what I'm looking for.

As it is currently configured, the container still displays when none of those conditions are met:
hidden link

and displays when one or all of the conditions are met:
hidden link

Which means the conditional arguments aren't appearing to do anything.

As an aside, I do have the wpv_condtional_post_has_content() function registered with the Front-end Content "Functions inside conditional evaluations" settings and have confirmed that this argument on its own is functional.

I'm wondering if it has something to do with my argument that utilizes the view, which the preview in the Gutenberg Blocks editor shows the output as `OR (' ' ne'')` (see attachment). If this is what the output on the frontend looks like, is there a way to work around this?

I'm sure I'm doing something wrong, though as far as I can tell, my syntax is correct since the AND conditions appear to work. Any help in this matter would be greatly appreciated. Thanks in advance!

#2686216

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL and admin access details and let me check what's going wrong with your setup.

OR condition will apply and it will display the container when any of the conditional is true. Any one of the condition becomes true it will display the container.

You want to display the container only when:
- post body content is not empty OR
- product type equal to variable OR
- The view "style-size-chart-content" returns empty value

Is that correct? if yes:

*** 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.

#2686638

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I did some further Googling, to attempt to find a solution to the problem, and I discovered that apparently views aren't designed to be used with the conditional logic system, according to this support thread: https://toolset.com/forums/topic/conditional-statements-based-on-view-shortcode-attribute-or-not-empty/

Christian Cox says, "Views aren't really meant to be used as the criteria for a conditional this way, and you're very likely to run into maximum nesting depth problems especially if you try to use another shortcode inside the View attribute."
====>
Maybe you misunderstood something here. It means you should avoid view's use as conditional argument. So you should not use view's shortcode inside [wpv-conditonal] shortcode as conditional shortcode conditional argument. You may have issues as view returns white spaces and when view return white spaces its not considered as empty.

Having said that - To overcome that limit - I've added the following shortcode to "Custom Code" section offered by Toolset:
- hidden link

add_shortcode( 'render-view', function($atts){
    
  $content = trim(render_view( array( 'name' => $atts['name']) ));
   
  return $content;
});

- The above shortcode will help us to get output of view and we will trim the white spaces from views output.

I've changed the conditional statement within your content template as given under and added the: [render-view name='style-size-chart-content'] as you can see below in the conditional statement

[wpv-conditional if="( wpv_conditional_post_has_content() eq '1' ) OR ( CONTAINS(#(product_type),'variable') ) OR ( '[render-view name='style-size-chart-content']' ne '' )"]

Where:
I've registered the above "render-view" shortcode at:
- Toolset => Settings => Front-end Content => Third-party shortcode arguments

More info:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

Can you please confirm it works as expected now.

#2686716

Excellent! It appears to be working as I was expecting it to. Thank you for your assistance!