Login Redirection for users with non-s2member roles

Hi,

I have some users that are not part of S2members roles. These users are customers from Woocommerce with the ‘customer’ role. When they login they are redirected to the membership sign up page. I tried overriding this behavior by using a redirection plugin called Peters login redirect.

However this doesn’t work because S2member takes full control of redirection. I would like customers to be taken to their my account page instead of the membership sign up page.

I’m also using BuddyPress, so the special URL redirection field in the ‘Login Welcome Page’ tab is already taken.

Help would be greatly appreciated.

Regards,
Emmanuel

General Options > Login Welcome Page = “Please choose a Page to be used as the first page Members will see after logging in.”

Hi,

Thanks for the help, but it doesn’t work. S2member won’t allow me to have a special redirection URL and Login Welcome Page set at the same time.

BuddyPress users should be redirected to: www.example.com/members/%%current_user_nicename%%/profile

Woocommerce customers should be redirected to: www.example.com/my-account
But they get redirected to membership sign up page (because they are not part of S2members custom roles and capabilities): www.example.com/membership-sign-up

Regards,
Emmanuel

Hi @unuigbee,

Do you have the Woo-Commerce My Account page restricted by s2Member? s2Member should only be redirecting visitors who attempt to access content they are restricted from accessing.

No it’s not restricted by s2Member but the BuddyPress profile is. When Woo-Commerce customers log in s2member attempts to redirect them (based on special redirection URL) to their BP profile because every user has a BP profile including customers. However they are automatically redirected to the membership sign up because the BP profile is restricted for non-s2member custom roles and capabilities.

Even though I don’t want customers getting taken to their BP profile, I also don’t want them being directed to the membership sign up page. I’ve taken measures to filter out users who are customers from showing as a BP member so they can’t access their BP profiles. I just haven’t solved the other issue of customers first getting directed to their BP profile and then membership sign up page.

It sounds to me like the solution to your problem lies in telling BuddyPress not to redirect Members from My Account to their profile on login then. I have set up BuddyPress for a couple of clients and I’ve never had it automatically redirect to the profile page. I’d check my BuddyPress settings and if that fails, check the BuddyPress docs, post on their forums, and/or send a support request to the BuddyPress devs.

s2Member is doing what it is supposed to do: redirect users from pages for which they have no access.

Thanks for replying but I don’t think that would solve my issue as s2member takes full control of login re-directs. I need to first clear up some confusion. The MyAccount page is a page created by WooCommerce for customers who want to check their orders made to the Shop and store their delivery information.

The main goal here is to separate shoppers/customers with customer accounts from subscribed BP members who have s2member level capabilities by a simple redirection on login to their respected pages.

As you already know, in the s2Member settings there is a setting for inputting a special redirection URL so that BP users gets redirected to their BP profile once they login. This special re-direction URL points to the BP profile of the logged in user.

BP is set up in a way where it treats every user as a BP Member if they at least have the capabilities to read. So S2member would recognise any user including shoppers that have customer accounts created through Woo-Commerce as a BP user. Hence why s2Member tries to direct customers to their BP profile but since they don’t have s2member capabilities they get re-directed to the Membership Sign Up page (So a double redirection).

I know that what s2Member is doing with regards to redirecting users with WC customer accounts is intended behaviour based on these two factors:

  1. WC shoppers with customer accounts are also BP members
  2. WC shoppers with customer accounts are not s2Members with level 1-5

I’ve been trying to see if I can hook into s2Members login redirect mechanism to make a special case for WC customers who login on the site.

Well, there is a setting that allows you to set a special redirection URL, but I did not know there was a separate setting to allow you to send all users to their BuddyPress profile.

I can’t help you with the custom code to create a special case for login redirects for WooCommerce Customers. Maybe @krumch can help. He is very good with s2Member code.

Yh that’s the setting i’m talking about the special redirection URL. I’ve set it to this: http://www.example.com/members/%%current_user_nicename%%/profile/
so that members get redirected to their BP profile. Circumventing this for other type of users would be nice.

Thanks @JediShark that you suggest me :slightly_smiling:

In this case only custom code may help - too specific, no easy way I know. @unuigbee, I can do, if you want me.

To get this working the way you want it, you need some custom coding.
What you can try to do, is modifying the template file of your loginpage by adding some PHP code.
When they login, check what role they have in Wordpress (there are basic Wordpress functions to do that: check de Wordpress Codex), and if they are customers from Woocommerce, provide a ‘wp_redirect()’ to direct them to the proper page(s).

If that doesn’t work you could also try to put that code on the s2Member membership sign up page (don’t know what PHP template that is, but you can look that up somewhere) so they get redirected again.

I’m not a very skilled PHP coder (I’m more of a copy-and-paste coder ;-)), so don’t ask me for example code. But googling on something like ‘how to check what user role someone has in Wordpress’ should give some decent answers to get you started.