WC_Customer() class not working

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”

Read More

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

Related posts

Leave a Reply

1 comment

  1. There is a fix with if( !is_admin() ) before, to test if your are on Back Office, because WC()->session isn’t set:

    if( !is_admin() ) { 
        $this_data = WC()->session->get( 'customer' );
        this->_data = $this_data;
    }
    

    Have you set before some data in it (you get this message because there is no data in it):

    if( !is_admin() ){
        $some_data = 'some_data';
        WC()->session->set( 'customer' , $some_data );
    } 
    

    Related threads: