diff --git a/plugins/woocommerce/changelog/issue-44852-session-to-login-action b/plugins/woocommerce/changelog/issue-44852-session-to-login-action new file mode 100644 index 000000000000..658b9b828446 --- /dev/null +++ b/plugins/woocommerce/changelog/issue-44852-session-to-login-action @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add the `woocommerce_guest_session_to_user_id` action hook that fires when a guest session is migrated to a customer ID diff --git a/plugins/woocommerce/includes/class-wc-session-handler.php b/plugins/woocommerce/includes/class-wc-session-handler.php index f39cf5106d92..55262bb44927 100644 --- a/plugins/woocommerce/includes/class-wc-session-handler.php +++ b/plugins/woocommerce/includes/class-wc-session-handler.php @@ -108,6 +108,20 @@ public function init_session_cookie() { $this->_dirty = true; $this->save_data( $guest_session_id ); $this->set_customer_session_cookie( true ); + + /** + * Fires after a customer has logged in, and their guest session id has been + * deleted with its data migrated to a customer id. + * + * This hook gives extensions the chance to connect the old session id to the + * customer id, if the key is being used externally. + * + * @since 8.8.0 + * + * @param string $guest_session_id The former session ID, as generated by `::generate_customer_id()`. + * @param int $customer_id The Customer ID that the former session was converted to. + */ + do_action( 'woocommerce_guest_session_to_user_id', $guest_session_id, $this->_customer_id ); } // Update session if its close to expiring.