Thanks for the message.
What’s your use case? Preserving carts and sessions doesn’t really work properly when switching between users.
There isn’t a means of disabling this functionality but I could add something in.
Hi John,
Thanks for the great plugin, it’s so useful. I also like that it’s really robust and professionally written with proper action hooks and support for filters.
Our use case: we often start building an order whilst logged in as staff, or not logged in at all. If we then discover that the customer already has an account, it’s really useful to be able to switch without losing the cart contents.
This worked really well until 1.5.0
What parts of preserving carts and sessions doesn’t work well in your experience?
Many thanks,
Jake
I’ve moved this functionality into actions in User Switching 1.5.2 so it can be unhooked:
add_action( 'init', function() {
remove_action( 'switch_to_user', [ user_switching::get_instance(), 'forget_woocommerce_session' ] );
remove_action( 'switch_back_user', [ user_switching::get_instance(), 'forget_woocommerce_session' ] );
} );
Thanks very much John.
Unfortunately it’s not working for me though. When I switch users, cart contents are lost.
I upgraded to 1.5.2 and copied your code above into a code snippet that runs everywhere with priority 10, that should work shouldn’t it?
(If I add items to the basket and then log in without using user switching, cart contents are preserved, so I know that is working fine).
Hmm, can you try changing init in the sample code above to plugins_loaded?
Thanks for the suggestion, that works perfectly now 🙂
Thanks for all your help John