Merge pull request #23001 from woocommerce/fix/22993

After logging in, update session customer ID
This commit is contained in:
Gerhard Potgieter 2019-03-14 09:26:00 +02:00 committed by GitHub
commit d8f32ff209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -67,7 +67,6 @@ class WC_Session_Handler extends WC_Session {
*/ */
public function init() { public function init() {
$this->init_session_cookie(); $this->init_session_cookie();
$this->_data = $this->get_session_data();
add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_cookie' ), 10 ); add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_cookie' ), 10 );
add_action( 'shutdown', array( $this, 'save_data' ), 20 ); add_action( 'shutdown', array( $this, 'save_data' ), 20 );
@ -91,6 +90,15 @@ class WC_Session_Handler extends WC_Session {
$this->_session_expiration = $cookie[1]; $this->_session_expiration = $cookie[1];
$this->_session_expiring = $cookie[2]; $this->_session_expiring = $cookie[2];
$this->_has_cookie = true; $this->_has_cookie = true;
$this->_data = $this->get_session_data();
// If the user logs in, update session.
if ( is_user_logged_in() && get_current_user_id() !== $this->_customer_id ) {
$this->_customer_id = get_current_user_id();
$this->_dirty = true;
$this->save_data();
$this->set_customer_session_cookie( true );
}
// Update session if its close to expiring. // Update session if its close to expiring.
if ( time() > $this->_session_expiring ) { if ( time() > $this->_session_expiring ) {
@ -100,6 +108,7 @@ class WC_Session_Handler extends WC_Session {
} else { } else {
$this->set_session_expiration(); $this->set_session_expiration();
$this->_customer_id = $this->generate_customer_id(); $this->_customer_id = $this->generate_customer_id();
$this->_data = $this->get_session_data();
} }
} }