My website requires users to complete their profile before they can place an order. So far, I have been able to redirect a user to his profile editing page if his profile is incompleted when he tries to place an order.
add_action('woocommerce_before_checkout_form',function(){
if (is_user_logged_in()){
$user = wp_get_current_user();
if ( bpprocn_has_incomplete_profile($user->id) ) { // check user's profile completed or not
if (wp_redirect(bp_core_get_user_domain( $user->id ) . bp_get_profile_slug() . '/edit/group/2')) exit;
}
}
});
Now I am trying to figure out how to redirect the user back to his cart page once he completes his profile.
I've found Wordpress's profile_update
action that could be used. The problem is, by using this action only, anyone updating their profile will be redirected, which is unwanted. I need to distinguish users who simply want to edit their profile from those users who try to place an order and get redirected to their profile editing page.
Does Wordpress provide anything in regards of this? The approach I can think of is mark a user as "try to place an order and get redirected" when he is redirected to profile editing page due to incompleted profile. I think to do this I need to access the session data. But my knowledge in this aspect is close to zero. Can anyone share some light or point me to a right direction? Thanks!