1

As the title states I'm trying to redirect users after they log in through the woocommerce login form to their respective custom pages (http://example.com/accounts/username)

So far I got this

add_filter('woocommerce_login_redirect', 'custo_login_redirect');
  function custo_login_redirect( $redirect, $user ) {
  $redirect = site_url( '/accounts/' . $user->user_login );
  return $redirect;
}

but it is only redirecting to "http://example.com/accounts/" and not using the username in the url at all.

Is there a way to make it work? Thanks for any help.

1
  • perhaps user_login is not available, check with has_prop, and if not, you'll have to get the user object using the ID, from the link: //Note: If called with the "id" or "name" parameter, the constructor queries the wp_users table. If successful, the additional row data become properties of the object: user_login, user_pass, user_nicename, user_email, user_url, user_registered, user_activation_key, user_status, display_name, spam (multisite only), deleted (multisite only). // codex.wordpress.org/Class_Reference/WP_User#Public_Properties
    – inarilo
    Jun 1, 2017 at 5:41

1 Answer 1

2

This worked perfectly:

add_filter('woocommerce_login_redirect', 'custom_wc_login_redirect', 10, 3);
  function custom_wc_login_redirect( $redirect, $user ) {
  $redirect = site_url() . '/accounts/' . $user->user_login;
  return $redirect;
}

Thanks everyone.

1
  • Thank you, this saved my life! Sep 2, 2019 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.