When I am logged in as a user on my woocommerce website and I try to create a new WC_Customer
, I get a fatal error telling me:
“Call to a member function get() on null”
I have tried to do this with a plugin as well as in the functions.php file of my theme, with the same result.
This is the line provoking the error, in the WC_Customer class:
$this->_data = (array) WC()->session->get( 'customer' );
Note: The website is still running locally
There is a fix with
if( !is_admin() )
before, to test if your are on Back Office, becauseWC()->session
isn’t set:Have you set before some data in it (you get this message because there is no data in it):
Related threads:
how to use session in woocommerce pages like we use normal php session?
WooCommerce WC()->session->get is not getting recognized