Allow notice to persist after customer ID change
This commit is contained in:
parent
5b3b285a9d
commit
eed91070b1
|
@ -954,7 +954,6 @@ class WC_Checkout {
|
|||
throw new Exception( $customer_id->get_error_message() );
|
||||
}
|
||||
|
||||
wp_set_current_user( $customer_id );
|
||||
wc_set_customer_auth_cookie( $customer_id );
|
||||
|
||||
// As we are now logged in, checkout will need to refresh to show logged in data.
|
||||
|
|
|
@ -66,6 +66,24 @@ class WC_Session_Handler extends WC_Session {
|
|||
* @since 3.3.0
|
||||
*/
|
||||
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 );
|
||||
add_action( 'wp_logout', array( $this, 'destroy_session' ) );
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup cookie and customer ID.
|
||||
*
|
||||
* @since 3.6.0
|
||||
*/
|
||||
public function init_session_cookie() {
|
||||
$cookie = $this->get_session_cookie();
|
||||
|
||||
if ( $cookie ) {
|
||||
|
@ -83,16 +101,6 @@ class WC_Session_Handler extends WC_Session {
|
|||
$this->set_session_expiration();
|
||||
$this->_customer_id = $this->generate_customer_id();
|
||||
}
|
||||
|
||||
$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 );
|
||||
add_action( 'wp_logout', array( $this, 'destroy_session' ) );
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,11 +121,11 @@ if ( ! function_exists( 'wc_create_new_customer' ) ) {
|
|||
* @param int $customer_id Customer ID.
|
||||
*/
|
||||
function wc_set_customer_auth_cookie( $customer_id ) {
|
||||
global $current_user;
|
||||
|
||||
$current_user = get_user_by( 'id', $customer_id ); // WPCS: override ok.
|
||||
|
||||
wp_set_current_user( $customer_id );
|
||||
wp_set_auth_cookie( $customer_id, true );
|
||||
|
||||
// Update session.
|
||||
WC()->session->init_session_cookie();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue