I'm not quite sure about when this exactly occurs since it only happens on the live server and not locally. But every now and then (few times per minute) i get a PHP notice in my debug.log
.
The PHP notice is: Trying to get property of non-object in /path/to/wordpress/wp-content/themes/themename/vendor/roots/sage-woocommerce/src/woocommerce.php on line 57
I even managed to pinpoint the exact problem, which is get_current_screen()->id
.
The strangest thing is, if i take the exact same actions on my local site as on the live site, locally i get 0 notices about this, but on the live site i get approximately 4 notices per minute. (due to it's a live site and people are ordering etc.)
Maybe also good to mention. The live site is hosted on cloudways and has it's own server.
I have tried requiring the require_once(ABSPATH . 'wp-admin/includes/screen.php');
in the sage woocommerce.php
file and var_dump(get_current_screen());
but this simply returns NULL
.
In time i tried many things to fix this issue, but to be honest it's been some time since i last tried this and i don't have any code left of this.
The exact code where this issue occurs in this file is:
add_filter('wc_get_template', function ($template, $template_name, $args) {
$theme_template = locate_template(WC()->template_path() . $template_name);
// return theme filename for status screen
if (is_admin() && ! wp_doing_ajax() && function_exists('get_current_screen') && get_current_screen() && get_current_screen()->id === 'woocommerce_page_wc-status') {
return $theme_template ? : $template;
}
// return empty file, output already rendered by 'woocommerce_before_template_part' hook
return $theme_template ? get_stylesheet_directory() . '/index.php' : $template;
}, 100, 3);
The plus side of this is, it doesn't break the possibility to order items, the down side is, i don't like this notice and it seriously fills the debug.log
I expect the ->id part to return 'woocommerce_page_wc-status' but as mentioned before, it simply returns NULL
no matter what i do.
Any help would be greatly appreciated since there are no articles/posts about this anywhere.