PHP Error on categories with 0 entries
-
Hi,
we get this error on woocommerce category archives if there is no product assigned:
Warning: Attempt to read property “post_type” on null in /home/swissma2/public_html/fasttransport/wp-content/plugins/ultimate-wp-mail/includes/UserManager.class.php on line 181
Could you please have a look on it in your Plugin? Thx
htaccess:
admin
hhomepageThe page I need help with: [log in to see the link]
-
Hi Alex,
That’s a strange one. I’ve never seen an issue like that before and it’s definitely not a global one in on our plugin. We’ve got the Ultimate WP Mail plugin enabled on our Woocommerce catalog demo site (https://www.etoilewebdesign.com/ultimate-woocommerce-catalog/) and it is not throwing that warning… You can see this here:
https://www.etoilewebdesign.com/ultimate-woocommerce-catalog/product-category/sample-category/
That WooCommerce category has no products in it.
(Debug is currently enabled on that site.)
And we have both the WooCommerce integration and the signup interests enabled.
Do you have those options enabled? Does it many any difference if you disable/enable them?
Also, how are you even ending up on an empty category when browsing your shop?
Hello @jaysupport,
if i disable your plugin the error is gone. The error is throwing in line 181 in the UserManager.class.php in your plugin and only in empty woocommerce categories. Please have a look on it!
Also to enable Woocommerce Integration und Listed Interests doesn’t help.
There is no caching enabled because it’s a development site on a dev server and no caching or file optimizations enabled.I also disabled all plugins except Theme, woocommerce and your plugin, it does’t change anything. So with Avada Theme, Woocommerce and your Plugin the error appears in the frontend.
I guess there is a conflict between Avada Theme and your plugin. But Avada is one of the most sold Themes ever so it should work also with that, correct?
For now i just edit the config.php to hide the error but that’s not really an solution isn’t it.
Thx Alex
Also, how are you even ending up on an empty category when browsing your shop?
Perhaps there is something specific to your setup that is causing it.
Hello @jaysupport,
just by going through the menu? There are static links to existing product categories.
Why it should have something to do with my setup if i only enable Avada, Woocommerce and your Plugin???
It is easy to say “not my plugin causes it” but infact it does in connection with just default Avada and default Woocommerce! Both major plugins/themes!
There is an argument which can’t be 0 so just change your Code to accept a null value as well or include a side step on checking this….there are ways to fix it.
Or do you want i write to Avada and Woocommerce to fix your plugin?
Cheers
- This reply was modified 2 years ago by alexqbox.
I’m definitely not trying to pass the blame. Nor did I say it isn’t our plugin causing it. We just can’t recreate it on any of our test sites, and have never heard of anything like this happening before, so were thinking that it’s likely something specific to your site/setup.
Anyway, that condition in our code returns the regular content that would have shown on the page if the post type is not “post”, as is the case on the WooCommerce category archive page. And, in the case where there are no products in a category, WooCommerce does still return content, in the form of a message that says something like: “No products were found matching your selection.” So the content is not null, at least not by default. If your content is null, then what is causing that? Does Avada have a specific theme template for WooCommerce category archive pages? If so, does it have a condition that alters what content shows when there are no matching products?
Would you be able to try changing that line (181 in UserManager.class.php) to the following?
if ( empty( $post ) or $post->post_type != 'post' ) { return $content; }
I’m not sure why the get_post is returning null on your site, but updating the condition as such should hopefully remove the warning even in that case.
Please let me know if that does the trick.
Hi again,
indeed it’s a special case and i don’t blame you as well! Your Plugin is great and as well as Avada part of our preset in our agency. But you know those lazy devs out there with always the same answers LOL
So by default woocommerce would give an notice like “no products found” on an empty archive. now Avada has the custom layout builder and there it’s possible to build your own page layout for example for archive pages. Inside is an element for the product view (grid) with it’s own notice. I just checked, this notice is empty inside Avada Layout. Now it would be just normal if Avada would take the woocommerce default instead of giving back 0. If i fill in something as a notice or if i use the default woocommerce archive layout, the error is gone.
Now i am between 2 chairs basically. Is it on Avada to not give back 0 or is it on your plugin to accept 0 but use an if argument to get around it. I am writing to the Avada support as well on that case.
We are using both Avada and your Plugin regulary. A future fix in any way would be nice. What do you think?
Cheers
- This reply was modified 2 years ago by alexqbox.
Thanks for getting back to me with that info. It definitely makes sense now. The updated condition I provided in my previously reply should actually take care of it. Are you able to make that change and test it?
Hi again,
here the answer from Avada Support:
As this is a 3rd party plugin, and we unfortunately cannot guarantee 100% compatibility with all plugins available. I am going to suggest that you please contact the plugin developer/author again regarding this. We simply do not have control over the plugins development or codebase. We would have checked but the plugin is not a known plugin and has only 1000 downloads.
Alright…with the new Code the error is gone! Will you update your plugin or do we need to keep it on our installation only?
Thanks!
Hi Alex,
Thank you for confirming. It’s a shame they didn’t address the reason for the null, but at least we know it works with our updated condition.
We’ll just need to run more in-depth tests to make sure there are no issues with the updated condition. After that we’ll include it in an update.
Hello @jaysupport
great! Thank you.
- The topic ‘PHP Error on categories with 0 entries’ is closed to new replies.