• Resolved BrianCS

    (@briancs)


    Hi John,

    I understand that any user with the “switch_user” privilege can switch user accounts using this plugin, and that a separate user role editor plugin can let me alter privileges like that. I have reason to grant that privilege to Customer accounts on a given WooCommerce site (explained next paragraph). But is there a way to limit which user accounts one can switch to by a factor such as user role? My main concern is to disallow any of my Customer user accounts for my WooCommerce site to switch to one of my Admin or Shop Manager accounts; I just want them to be able to switch between other Customer accounts only.

    What I’m trying to accomplish: my client wants me to build a wholesale order portal with WooCommerce. He specifically wants me to allow multiple sales reps to make wholesale orders with one “master” account and password that can access a couple hundred customer accounts. My design thought at the moment is to create a “master” user account for all sales reps to login to. When they log in, they’re redirected and granted access to a Pick a Customer page that contains a list of clickable/tappable buttons for all Customer user accounts in the system. By tapping or clicking a customer button, I want the site to switch to that customer account automatically, invisible to the end user or entirely behind the scenes (i.e. without requiring another login process besides the “master account” login) so that the correct customer, postal address, payment method, etc. is processed with the order. After clicking the customer button, it’ll take them to a bulk order page (i.e. I’m eyeballing this one: https://rapidorderplugin.com/).

    I’ve been developing WordPress sites for over 3 years now, but haven’t had to tackle this much of a challenge before (I mostly do custom themes). Thanks so much for any help.

    Peace,
    Brian

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

    (@johnbillion)

    WordPress Core Developer

    Thanks for the message.

    This is possible but you’ll need to get a developer to implement the necessary filtering in code, rather than solely relying on granting the switch_user capability to the user.

    The main code to look at is the user_switching::filter_user_has_cap() method which controls the existing logic inside User Switching. You can duplicate this method into your own function and hook it into the same user_has_cap filter that User Switching uses, and then tweak the logic according to your needs.

    I hope you understand that this sort of fine grained, custom control isn’t the sort of thing that User Switching can support out of the box.

    John

    Thread Starter BrianCS

    (@briancs)

    Thanks John,

    It’s great to know where to start looking as far as hooks and filters go. I’ll check it out and see if I can handle it myself (I have done some light plugin development work before).

    And I certainly do get it, no worries. I do appreciate the help. Thanks so much.

    Peace,
    Brian

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Limit Target User Account Access?’ is closed to new replies.