Skip Navigation

[Gelöst] Views Conditional Shortcode has term not working with WooCommerce for me.

This support ticket is created vor 8 Jahre. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 12:00 8:00 – 10:00 8:00 – 14:00 8:00 – 14:00 8:00 – 12:00 -
- 13:00 – 18:00 11:00 – 18:00 15:00 – 18:00 15:00 – 18:00 13:00 – 18:00 -

Supporter timezone: Pacific/Pago_Pago (GMT-11:00)

This topic contains 12 Antworten, has 3 Stimmen.

Last updated by benH-6 vor 8 Jahre.

Assisted by: Mladen Andrejic.

Author
Artikel
#378166

I am trying to display certain views shortcodes if the following conditional is true.

If product IS IN product_cat "Reports".

[wpv-conditional if="( has_term('Report', 'product_cat', null) eq '1' )" ]

The above doesn't work for me.

The below link shows someone doing something similar but checking the parent, that also doesn't work, I tried her final function. I have also tried the recommended examples on https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/ and other documentation on the website and nothing works. It just returns false even if the product is in the Reports product category and thus the elements don't show.

<div class="single-product-data">  
<p><strong>Category:</strong> [wpv-post-taxonomy type='product_cat']</p>
<p><strong>Tags:</strong> [wpv-post-taxonomy type='product_tag']</p>
[wpv-conditional if="( '[wpv-taxonomy-slug]' eq 'reports' )"] 
<p><strong>Topic:</strong> [wpv-post-taxonomy type='topic']</p>
<p><strong>Type:</strong> [wpv-post-taxonomy type='product-type']</p>
<p><strong>Companies:</strong> [wpv-post-taxonomy type='company']</p>
<p><strong>Report Class:</strong> [wpv-post-taxonomy type='report-class']</p>
[/wpv-conditional]
</div>

https://toolset.com/forums/topic/urgent-please-need-to-set-conditional-to-check-for-parent-taxonomy-term/#post-378084

#378240

Hello David,

I think that you forgot to register the function you're using.

On this page : https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ you will see "Inside the evaluation expression, you can use any of the following:"

And there is the complete list of the things you can use, please check that, register your function with Views and give it a try.

Thanks.

#378357

Okay, is that in reference to my first attempt at the top of my post or the code in the second box?

So I need to register "wpv-taxonomy-slug"?

to do that, do I click the conditional output button, then go to "settings" and then put wpv-taxonomy-slug into the "Function name" box and add it? What does that do? I thought the wpv-taxonomy-slug function was one existing within views or toolset?

Can you give me a brief step by step?

Thanks

#378484

I still can't seem to quite work this out. Can you help? Maybe support is closed for the weekend or Easter? Anyway Happy Easter. I really need to progress with my project over the next couple of days so hoping to hear back.

#378546

Hello,

Happy Easter!

Sorry for the delay, we are not working on weekends in general.

Yes, but has_term is WordPress function, so you will have to register it with Views and then it should work.

Can you please give it a try?

Thanks.

#378665

No problem.

I am not sure what that means or involves? What is the function? I thought all the shortcodes provided by Views were recognized by views? What and where do I register that? Is there a step by step guide?

#378785

Hello,

On this page, just find section "Checking for a taxonomy term" and there you have a complete guide for has_term and this might answer your question completely.

https://toolset.com/documentation/user-guides/getting-started-views/part-6-conditional-statements-in-views/

Thanks.

#379012

Okay yes, I see that now. I went there and added the has_term function however my conditional

 [wpv-woo-product-image size="shop_single" output="" gallery_on_listings="no"]
<div class="summary entry-summary">
<h1>[wpv-post-title]</h1>
[wpv-woo-product-price]
[wpv-woo-buy-options add_to_cart_text="Purchase"]
<div class="single-product-data">  
<p><strong>Category:</strong> [wpv-post-taxonomy type='product_cat']</p>
<p><strong>Tags:</strong> [wpv-post-taxonomy type='product_tag']</p>
[wpv-conditional if="( has_term('Report', 'product_cat', null) eq '1' )" ]
<p><strong>Topic:</strong> [wpv-post-taxonomy type='topic']</p>
<p><strong>Type:</strong> [wpv-post-taxonomy type='product-type']</p>
<p><strong>Companies:</strong> [wpv-post-taxonomy type='company']</p>
<p><strong>Report Class:</strong> [wpv-post-taxonomy type='report-class']</p>
[/wpv-conditional]
</div>
</div>

still doesn't seem to work. Is there anything I am doing wrong?

The taxonomy is product_cat from WooCommerce and my term is Reports, but these two details don't seem to work. Is there a problem if it is in both

Reports
- Sub Report

So its in two categories, does this effect it?

What is the purpose of null and eq 1 in the below line?

[wpv-conditional if="( has_term('Report', 'product_cat', null) eq '1' )" ]

Thanks

#379017

Maybe this is why this person created a function for post_is_in_taxonomy_slug

https://toolset.com/forums/topic/urgent-please-need-to-set-conditional-to-check-for-parent-taxonomy-term/#post-378084

Is that the only way to make it work with WooCommerce? Perhaps it doesn't understand the nicename Reports and so needs to be redone as a slug?

#379076

Hello,

If you registered has_term in Views Settings then this should perfectly work. However, I don't see you pasted TAG enclosure [/wpv-conditional] at the end of the code snippet.

This might sound like funny mistake, but it happens a lot that people focus on harder things that they done good and forgot some minor, but still crucial things.

Please make sure that you've closed the tag.

Thanks.

#379244

Can you not see it on line 14 above?

#379395

Hello,

Sorry, yes there it is.

In order to be of a better help I will need to request temporary access (WP-Admin and FTP) to your site.

You will find the needed fields for this below the comment area when you log in to leave your next reply.


The information you will enter is private which means only you and I can see and have access to it.
// NOTE : Make sure that you have performed the backup before you let me access the site.

Thanks.

#584117

I wonder what the solution was here? I'm having a similar issue with [wpv-woo-buy-options] in a conditional output. I'll start a new ticket though.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.