I’ve just moved an e-commerce WordPress site that uses the WooCommerce plugin to another server and, when going to view the new site, I started receiving the following error:
PHP Fatal error: Call to a member function is_visible() on a non-object in /public_html/wp-content/plugins/woocommerce/templates/content-product.php on line 23
I checked the template file at the point where the error was occuring and this is what I found:
// Ensure visibilty if ( ! $product->is_visible() ) return;
After commenting out these lines it simply then failed at the next $product related function. Next I tried checking whether $product was set:
var_dump($product); // Output: NULL
Weird. It worked fine on the development server, so why would it suddenly break after moving it? Luckily the solution is an easy one (if not a little odd) …
The Solution
The above problem can be resolved by simply navigating to ‘Plugins’ within WordPress, deactivate the WooCommerce plugin and then re-activate it. What it’s doing exactly I’m not sure, however after performing these steps the errors stopped and site returned to how it should be.