• Hi Team,

    I have a WooCommerce website where I’ve implemented a custom user account page with a special URL structure like domain.com/username. Now, I want to redirect users after OTP login to their respective accounts. However, I’ve encountered an issue with your xoo_ml_login_with_otp_redirect function. I need to retrieve the user object or userID in order to achieve this.

    Here’s an example of what I’m trying to achieve:

    $redirect = wp_validate_redirect( apply_filters( 'xoo_ml_login_with_otp_redirect', sanitize_url( $redirect ), $user ) );

    Thank you for the great plugin!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author xootix

    (@xootix)

    Hello Mohammad,

    Unfortunately $user argument is not available in the existing version, I will make sure to add it in the next update.
    Until then, please use this snippet to get the $user object.

    add_filter( 'xoo_ml_login_with_otp_redirect', function( $redirect ){
    
    	$otp_data 	= Xoo_Ml_Otp_Handler::get_otp_data();
    
    	$user 		= xoo_ml_get_user_by_phone( $otp_data['phone_no'], $otp_data['phone_code'] );
    
    	if( $user ){
    
    	}
    
    	return $redirect;
    
    } );
    Thread Starter Mohammad Limon

    (@mlimon)

    That would be great if it’s included, and yes, I’m already using the same method.

    function ml_xoo_ml_login_redirect($redirect)
    {
        $otp_data = Xoo_Ml_Otp_Handler::get_otp_data();
        $user = xoo_ml_get_user_by_phone($otp_data['phone_no'], $otp_data['phone_code']);
        if ($user) {
            return home_url('/' . $user->user_login);
        }
    
        return $redirect;
    }
    add_filter('xoo_ml_login_with_otp_redirect', 'ml_xoo_ml_login_redirect');

    However, I misunderstood before, thinking that it might cause one notice and one warning. But later, I understood that it actually has nothing to do with this filter; those two errors are coming from the main plugin.

    Could you please address these two (warning & notice) ?

    PHP Warning: array_map(): Expected parameter 2 to be an array, null given in \var\sitelocation\wp-content\plugins\mobile-login-woocommerce\includes\class-xoo-ml-geolocation.php on line 25
    PHP Notice: Trying to access array offset on value of type null in C\var\sitelocation\wp-content\plugins\mobile-login-woocommerce\includes\class-xoo-ml-otp-handler.php on line 24

    That would be really helpful

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect the user to their respective account’ is closed to new replies.