From 203dba5a1fa99014668dc9db8776c363c992ff21 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 12 Mar 2019 16:36:15 +0000 Subject: [PATCH] After logging in, migrate session data --- includes/class-wc-session-handler.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-session-handler.php b/includes/class-wc-session-handler.php index 0d4ebfd0460..1fcd28d8014 100644 --- a/includes/class-wc-session-handler.php +++ b/includes/class-wc-session-handler.php @@ -67,7 +67,6 @@ class WC_Session_Handler extends WC_Session { */ public function init() { $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( 'shutdown', array( $this, 'save_data' ), 20 ); @@ -91,6 +90,15 @@ class WC_Session_Handler extends WC_Session { $this->_session_expiration = $cookie[1]; $this->_session_expiring = $cookie[2]; $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. if ( time() > $this->_session_expiring ) { @@ -100,6 +108,7 @@ class WC_Session_Handler extends WC_Session { } else { $this->set_session_expiration(); $this->_customer_id = $this->generate_customer_id(); + $this->_data = $this->get_session_data(); } }