• Resolved w4yp01nt

    (@w4yp01nt)


    Hello,

    I have a bit of a pre-purchase question which I would think would be a common problem/feature request with this type of plug-in, but it does not look like it is possible to solve out of the box. I am playing around with the free version right now to see if it will accommodate my needs. If it does, I will get the PRO version.

    I have a wholesale site where there are different user tiers. These are assigned by user role. An example:

    User Role A -> Has one price, one payment option in the checkout
    User Role B -> Has a different price, more payment options in the checkout
    User Role C -> And so on.

    Now my issue is, that every time a customer (A parent account, representing an entire company with multiple subaccounts) should be upgraded from User Role A to User Role B for example, the subaccounts would have to be upgraded manually from the looks of it.

    Is there any way for this plug-in to let subaccounts inherit their user role from the parent account?

    Side note (Just FYI): I had a lot of issues getting my user roles to be selectable within your plug-in, they did not appear after adding define('SFWC_VALID_ROLE_LOOSE_MODE', true); to my config file either.

    I dug into your code and realized that you check for the presence of the array keys (not the values) of edit_posts and delete_posts in the user capabilites, yet these are added by default as false, when you use the default wp add_role function to add your roles. Just something for you to be aware of perhaps – it might make sense to check for the keys and then additionally if they are false if they are there ??

    • This topic was modified 1 month, 1 week ago by w4yp01nt.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter w4yp01nt

    (@w4yp01nt)

    I came up with this, would it be a stable approach to simply check these fields?

    Plugin Author mediaticus

    (@mediaticus)

    Hi @w4yp01nt,

    Thank you for reaching out!

    I had a look at your code, thanks for contributing to the plugin. Your approach seems good, other users may find it useful as well. ??

    We are also planning to add a new option in the backend plugin settings page, which will allow the admin to decide whether subaccounts should inherit the manager (parent account) role when a new subaccount is created on the frontend. This could be useful in your case.

    Regarding the possibility to enable additional roles, we will soon allow developers to add additional roles among the enabled ones via add_filter.

    If you have any other questions about the plugin, just let us know.

    Thread Starter w4yp01nt

    (@w4yp01nt)

    @mediaticus Thanks for having a look!

    The other thing you mentioned, is a problem I have taken a stab at solving as well, since I need to do this when accounts are created, as you pointed out. Due to timing issues (Related to when the children meta is actually written), the only solution I could hack together was this one.

    Please let me know if you see a better way to do this as well ??

    Plugin Author mediaticus

    (@mediaticus)

    Hi @w4yp01nt,

    Could you please try the snippet of code below and let us know if it works as expected?

    // Make subaccounts created on frontend inherit user roles from the parent account.
    add_action( 'sfwc_frontend_after_add_subaccount_validation', 'm3di4ticus_inherit_parent_roles_on_frontend_subaccount_creation', 10, 2);
    function m3di4ticus_inherit_parent_roles_on_frontend_subaccount_creation( $parent_user_id, $user_id ) {
    if ( is_user_logged_in() ) {

    // Get parent account data.
    $parent = get_userdata( $parent_user_id );

    // Get subaccount data.
    $subaccount = get_userdata( $user_id );

    // Get parent account role(s).
    $parent_roles = sfwc_is_user_role_valid( $parent_user_id );

    // Set parent's roles.
    if( ! empty( $parent_roles ) ) {

    foreach( $parent_roles as $parent_role ) {

    $subaccount->add_role( $parent_role );
    }
    }
    }
    }

    Important note: The above functionality will soon be included in the plugin. To avoid any conflicts or race conditions, remember to remove the above code from your functions.php file or from any code snippet plugin (you can take a look at our plugin’s changelog to see if the above functionality is present).

    Hope this helps.

    Plugin Author mediaticus

    (@mediaticus)

    We haven’t heard from you in a while so I’m going to go ahead and mark this thread as resolved.

    If you have any other questions about the plugin, please start a new thread.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.