[Enhancement]: New Action to fire before WC_Session_Handler converts a guest session to login. #44852
Labels
focus: my account
Issues related to my account page.
priority: normal
The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc.
team: Proton
type: enhancement
The issue is a request for an enhancement.
type: good first issue
The issue is a good candidate for the first community contribution/for a newcomer to the team.
Describe the solution you'd like
I'd like to request an action be slipped in to fire either in in WC_Session_Handler::save_data()
woocommerce/plugins/woocommerce/includes/class-wc-session-handler.php
Lines 349 to 375 in 487c7a8
woocommerce/plugins/woocommerce/includes/class-wc-session-handler.php
Lines 83 to 123 in 487c7a8
guest_session_id
is getting blown away and its data transferred to auser_id
.Something like
do_action( 'wc_migrate_guest_session_key', $old_session_key, $user_id );
or the like.This would let third-party code either connect the prior session key to a user id for data storage, or migrate the old session id to a different cookie that would enable discrete sessions even if multiple browsers authenticated to the same user_id.
Describe alternatives you've considered
If this isn't considered, I've evaluated doing a much messier workaround, that being duplicating the session key in a side channel, and watching for it to change or for there be a logged in user concurrent with it, and try to ensure I'm catching the event before WooCommerce clears it, but it feels very ... klunky, liable to race conditions, and adding overhead to every page load.
Additional context
For plugins that are providing additional context on user flows, the ability to be connect the pre-login result of
WC()->session->get_customer_unique_id()
to the post-login result where it returns auser_id
instead can ensure a more seamless experience for customers without overcomplicated workarounds.The text was updated successfully, but these errors were encountered: