Merge pull request #23687 from rekkitatu/master
Delete guest cart session if user logs in, solves #23686
This commit is contained in:
commit
043fd478bc
|
@ -94,9 +94,10 @@ class WC_Session_Handler extends WC_Session {
|
|||
|
||||
// If the user logs in, update session.
|
||||
if ( is_user_logged_in() && get_current_user_id() !== $this->_customer_id ) {
|
||||
$guest_session_id = $this->_customer_id;
|
||||
$this->_customer_id = get_current_user_id();
|
||||
$this->_dirty = true;
|
||||
$this->save_data();
|
||||
$this->save_data( $guest_session_id );
|
||||
$this->set_customer_session_cookie( true );
|
||||
}
|
||||
|
||||
|
@ -234,9 +235,11 @@ class WC_Session_Handler extends WC_Session {
|
|||
}
|
||||
|
||||
/**
|
||||
* Save data.
|
||||
* Save data and delete guest session.
|
||||
*
|
||||
* @param int $old_session_key session ID before user logs in.
|
||||
*/
|
||||
public function save_data() {
|
||||
public function save_data( $old_session_key = 0 ) {
|
||||
// Dirty if something changed - prevents saving nothing new.
|
||||
if ( $this->_dirty && $this->has_session() ) {
|
||||
global $wpdb;
|
||||
|
@ -253,6 +256,9 @@ class WC_Session_Handler extends WC_Session {
|
|||
|
||||
wp_cache_set( $this->get_cache_prefix() . $this->_customer_id, $this->_data, WC_SESSION_CACHE_GROUP, $this->_session_expiration - time() );
|
||||
$this->_dirty = false;
|
||||
if ( get_current_user_id() != $old_session_key && ! is_object( get_user_by( 'id', $old_session_key ) ) ) {
|
||||
$this->delete_session( $old_session_key );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue