Skip Navigation

[Gelöst] WooCommerce search error with WP Views activated

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

This topic contains 16 Antworten, has 3 Stimmen.

Last updated by willem-siebeS vor 8 Jahre, 5 Monate.

Assigned support staff: Luo Yang.

Author
Artikel
#234016

Hi,

I have build a WooCommerce shop, when using the search field from the woocommerce search widget, there are no problems when you search for something they can find. However, if you search something that does not give results, you get a white page with this error:

Fatal error: Call to a member function is_visible() on a non-object in /home/wsintern/public_html/keratinehaarproducten.nl/wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 45

Deactivating WP Views solves the problem, but that is ofcourse not a solution ;-). Hope this can get solved quickly, because website is going live in a few days.

Kind regards,

Willem

#234017

For the record: that WP Views is installed is NOT the problem, the problem is the actual 'Wordpress Archive' that is assiged to 'post type archive' 'products'.

#234074

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi Willem,

Are you using Views stable version 1.6.1?
Could you try deactivate other plugins except Views & Woocommerce and switch to wordpress defualt theme, and test again?
If the problem still exists, please try describe detail steps to duplicate same problem, or duplicate same problem in a test site, and fill below private details box with login details, also point out the problem view URL and problem page URL, I need a live website to debug this problem, thanks

#234078

Are you using Views stable version 1.6.1?

Yes.

Could you try deactivate other plugins except Views & Woocommerce and switch to wordpress defualt theme, and test again?

I did, I even did a clean install and the problem is exactly the same.

If the problem still exists, please try describe detail steps to duplicate same problem, or duplicate same problem in a test site, and fill below private details box with login details, also point out the problem view URL and problem page URL, I need a live website to debug this problem, thanks

I have a testsite for you. You don't need to do any steps, but just need to enable and disable the checkbox that assign the wordpress archive to the 'products' post type archive. That is causing the problem. You have to add the testwebsite to your hosts file though. I have send you a seperate email with instructions.

#234447

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Thanks for the details, I am trying to logging into your website, will feedback if there is any found.

#234639

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Are we talking about goto the wordpress archive:
hidden link
in section "Post Type Archives", disable/enable option "Products", I tried it, and click "update" button, but can not get any error message

And I can not see any widget which act as "woocommerce search widget", could you point out the problem page URL? thanks

#234646
2014-08-05_15-01-45.jpg
2014-08-05_15-00-12.jpg
unnamed.jpg

See images. Explained everything in the there.

#234840

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Thanks for the details, I got the error message in your website, and trying to duplicate same problem in my localhost, will feedback if there is any found.

#235006

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

I have been able to duplicate same problem in my localhost, and put it into our to-do list, our developers will take care of it.

#235009

Thanks Luo, can you maybe provide me with temporary hack if possible? As you understand this is not good for a livesite ;-). Hope it's possible.

Kind regards,

Willem

#235011

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Please edit the woocommerce file /plugins/woocommerce/includes/wc-template-functions.php, try this:

Replace line 42 from:

elseif ( is_search() && is_post_type_archive( 'product' ) && apply_filters( 'woocommerce_redirect_single_search_result', true ) && $wp_query->post_count == 1) {

to

elseif ( is_search() && is_post_type_archive( 'product' ) && apply_filters( 'woocommerce_redirect_single_search_result', true ) && $wp_query->post_count == 1 && isset($wp_query->post)) {
#235019

That worked, thanks!

#235217

Luo Yang
Supporter

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Please let me know if you need other assistance, and the problem is still in our to-do list, there isn' response from our developers, I will update this thread if there is any news

#236088

Juan
Supporter

Timezone: Europe/Madrid (GMT+01:00)

Hi Willem

This is Juan, lead Views developer. Sorry it took me so long to get back to you, we are quite far in the dev cycle and new development is already frozen for Views.

First things first. I see that Luo provided a workaround that solved temporarily your issue. The problem with this workaround is that you needed to hack the WooCommerce code, and as soon as they release an update you will be back to square one. Hacking core files from plugins is never a good solution on the long run.

But I have good news: I already implemented a fix which will be included in our next Views release. There is a way for you to have that fix available right now, if you want to. You will need to install our latest beta (Views 1.6.2 beta 2, from your user account downloads page) and then replace one file with the one I would send you to your email as soon as you confirm me that you are interested 🙂 That beta version is quite stable, as it already passed our dev tests and QA tests and it is just waiting for the whole Toolset family to be ready (we want to do a complete release), so it should be safe to use it.

Just for your information, let me explain what is causing this issue and how we solved it.

For archive pages (and the one having issues is a search results archive page) using a WordPress Archive from Views, we do some tricks to replace the actual loop with our own. There is an edge case: when no results are returned. In this case, we can not do our magic so easily, so we need to fake a result, display out loop (that will likely just display the "No posts found" message) and clean the results again after that.

Now, WooCommerce has a feature that, when the search just returns one products, will redirect the search result page to the single only resulting product page. You can see we will have a problem here.

So, when those two features are used at once, WooCommerce tries to load the single page for a faked product that we created, so that fake product lacks some properties that WooCommerce relies on, bringing us the disaster 🙂 The good news is that WooCommerce provides a handy way to disable that functionality. Our solution is basically to check if using a WordPress Archive and also if the actual loop contains any result, and if both conditions are happening, we use the handy WooCommerce filter to disable that redirect feature. This means that it will have no other side effect whatsoever.

Sorry for the long write, and I will be waiting for your response to send you the hotfix in case you want to use it.

Regards,
Juan de Paco

#240785

Hi Juan,

Ok, I see changelog v. 1.6.2:

- Compatibility: WooCommerce
* fix product search results when there are no results and using a WordPress Archive

Tested the update ofcourse and it works.

Thanks for all your explenation, very interesting to read.

One thing though, I tested to see if the redirect to one product is still working after the update, and it does work perfectly. But you say:

Our solution is basically to check if using a WordPress Archive and also if the actual loop contains any result, and if both conditions are happening, we use the handy WooCommerce filter to disable that redirect feature. This means that it will have no other side effect whatsoever.

But did you mean 'and also if the actual loop contains more then one result' maybe?? Because with one result, you won't disable that redirect feature when I'm right?

Kind regards,

Willem