Skip to content

Commit

Permalink
Tokenized Cart - update customer ID when user logs in (#9218)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmoore committed Aug 6, 2024
1 parent c89d7de commit 582e857
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/fix-9145-tokenized-cart-customer-id-mismatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Fix for unreleased tokenized cart feature


11 changes: 10 additions & 1 deletion includes/class-wc-payments-payment-request-session-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ public function init_session_cookie() {
// If an account has been created after the session has been initialized, update the session.
// This method is called directly by WC blocks when an account is created right before placing an order.
$previous_session_data = null;
parent::init_session_cookie();

if ( is_user_logged_in() && strval( get_current_user_id() ) !== $this->_customer_id ) {
$previous_session_data = $this->_data;
/**
* This is borrowed from WooCommerce core, which also converts the user ID to a string.
* https://github.com/woocommerce/woocommerce/blob/f01e9452045e2d483649670adc2f042391774e38/plugins/woocommerce/includes/class-wc-session-handler.php#L107
*
* @psalm-suppress InvalidPropertyAssignmentValue
*/
$this->_customer_id = strval( get_current_user_id() );
}
parent::init_session_cookie();

$this->init_session_from_token();
if ( ! empty( $previous_session_data ) ) {
$this->_data = $previous_session_data;
Expand Down

0 comments on commit 582e857

Please sign in to comment.