Okay
  Public Ticket #3562142
Assign Sales Rep Based on User Role
Open

Comments

  •  2
    Ben started the conversation

    I have a user 

    joibentitou - that is a sales rep. She is going to be the rep for all accounts that register as "Retail".  I have a form that creates these users , and I need salesking to assign her as the rep for ALL customers that register as Role Type Retail.. 



    Can we do that in Sales King? 

  •  2
    Ben replied

    Ok, I'm going to fine tune it a bit further. on our customer registration form it asks what customer type they are. If they choose CBD Store , I would like have those all go to a single sales agent  . joibentitou user 

  •  1,892
    WebWizards replied

    Hi Ben,


    I believe we may be able to help set this up through a code snippet.


    I understand that you want all customers who register as Role Type Retail OR as CBD Store to be automatically assigned to the agent joibentitou.


    To be able to write the snippet, I need some information:

    - Can you please send me a link to the registration form on your site? 

    - And what is the user ID of the joibentitou user?

    The user ID can be seen in the URL when you edit the user:

    get-user-id-in-wordpress-admin-url.png


    Kind regards,

    Stefan

  •  2
    Ben replied

    Link to Register : 

    https://partner.americannawellness.com/register

    User ID : 

    salesking_role_6548

  •  1,892
    WebWizards replied

    Thank you for the details,

    Please note salesking_role_6548 does not look like a user ID. It should be a number such as 102 in the URL as in this screenshot:

    8642913516.png

    You would see this when going to the site backend -> Users and clicking on the joibentitou user.


    Please try to find that number and then add this code snippet to your site:

    add_action('woocommerce_created_customer', 'save_custom_registration_fields');
    add_action('user_register', 'save_custom_registration_fields');
    function save_custom_registration_fields($user_id){
        $val = sanitize_text_field($_POST['radio_1700848552']);
        if (assign_agent($val)){
            update_user_meta($user_id, 'salesking_assigned_agent', 'salesking_role_6548');
        }
    }
    function assign_agent($val) {
        // Check if $val contains 'CBD' or 'Retail' regardless of case
        if (stripos($val, 'CBD') !== false || stripos($val, 'Retail') !== false) {
            return true;
        }
        return false;
    }
    

    Replace salesking_role_6548 in the code with the user ID number.


    A PHP snippet can be added to functions.php, or by following our guide here: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/



    Kind regards,

    Stefan


  •  2
    Ben replied

    Ok, Can I assign a sub agent to multiple main agents? 


    example user 126 needs to be subagent for the following agents 

    251,281,249 & 250... 


    The system will only allow me to add 1 agent per subagent ? I've tried putting commas and it wont accept it. 



    5437816370.png


  •  1,892
    WebWizards replied

    A subagent can only have a single parent agent I'm afraid - this is just how the plugin works at a basic level, it defines relationships as parent - child, and a child can only have a single parent.

    Can you let me know more about what you are trying to achieve?

    Are you trying to set commissions in a certain way?

  •  2
    Ben replied

    Yes 

    We have different types of Sales people We have an Inside Sales Rep , Field Rep, etc. 


    You may have 1 ISR mapped to 3 different Field Reps.

    a. To setup appointments for the field rep to go close 

    b. To reach out to their own clients , that are separate from the field reps they support. 



    In that Scenario , the ISR would need to be the sub agent of 3 Field Reps. The reason why is .... 


    The Field rep is going to get 25% of the order total. 

    The ISR if they're a subagent , they get 5% of the order total 


    If the ISR is not the sub agent , and there is no field agent, then the ISR gets the full 25%. 


    If the ISR is the sub agent of the Field Rep, the field rep gets 25% of the order total , and the ISR gets 5% , AND if its the first time this customer has purchased , and its an Field Rep/ ISR Combo client, then the ISR gets $50 ontop of the 5% but only for that clients first order. 




    So in summary: 

    Field Reps get the full 25% if they are on the deal. 


    ISR's can get either 25% if there is no Field Rep on the order , OR 

    ISR's can get 5% + $50 one time kicker on customers first order. 



    If you can help me get to that , I will be a very happy customer. 


    The LAST thing I need to do is figure out a way to automate the ISR or ISR/Field Rep designation , So I don't have to manually go into WooCommerce after every single registration , and look up the region , reach out to the Field Rep or ISR to find out if they are shared or not. Then I have to assign the rep before the customer places an order , otherwise I have to go in and manually add everything , which happens more often than I'd like to admit. 



  •  1,892
    WebWizards replied

    Thank you for the details,


    I think the closest option available would be to set it up as follows:

    - ISR is the parent agent to 3 field reps, which are subagents of the ISR.


    You could then create a general rule for 25% commission + 1 rule for 5% commission on subagents' orders.


    The result should be:

    - If the order belongs to the ISR with no field rep, the ISR gets 25%

    - If the order belongs to the field rep, the field rep gets 25%, ISR gets 5%

    However I don't think there's a way to set the $50 on the customer's first order, for that a new condition would be needed in the plugin.

    If you'd like, I can send details / screenshots with the rule configurations for the above.


  •  2
    Ben replied

    Yes I need some help on this.... 


    We just hired a bunch of new employees... Can sales king support this type of architecture .....


    Alfredo will get 3% on ALL orders that are placed 

    ISR 1 - Joi gets 25% on all orders she is on - Alredo needs the 3% off this order 

    ISR 2 - Traci gets 15% on all orders she is on - Alfredo needs the 3% off this order 

    ISR 3 - Roger gets 15% on all orders he is on - Alfredo needs to get the 3% off this order 

    ISR 4 - Traci gets 15% on all orders she is on - Alfredo gets his 3% off these orders 

    ISR 5 - Kelsey gets 15% on all orders she is on - Alfredo gets his 3% off these orders ..... 



    Is the setup as follows? 


    SalesGroup 1 - 25% on all orders 

    SalesGroup 2 - 15% on all orders 

    Sub Agent Group - 3% assigned to all Agents? 



  •  1,892
    WebWizards replied

    Hi Ben,


    For the user Alfredo to get a 3% on all orders placed, it is needed that all other agents (Joi, Traci, Roger, etc) are subaccounts of Alfredo.

    Then yes, you can set 3 rules for:

    SalesGroup 1 - 25% on all orders 

    SalesGroup 2 - 15% on all orders 

    + a rule for 3% for subagent orders

    Another option: It may be possible for us to write a code snippet to programmatically directly give the user Alfredo 3% from the value of all orders (regardless of who is a subaccount of who or who the customer is). I can check that and get back to you - let me know if it would help.


    Kind regards,

    Stefan

  •  2
    Ben replied

    That would be great until Alfredo doesn't work here anymore, and we have to use a different user. If we were able to set it up on our end, lets say we get a new alfredo , we can just create the new user , assign the 3% and add all the sub agents 

    right? 


  •  1,892
    WebWizards replied

    In that case where the user Alfredo has to be changed, I think you would have two options:

    - Possibly the easiest: keep the same user but just change the username / email of the account. Then no other changes would be needed.

    - If you need to set a new user, then yes you would change the user in the 3% rule, and then would need to move all other agents to be subagents of the new user. This can be done in SalesKing -> Settings -> Tools -> "Set users as subagents of an agent".

  •  2
    Ben replied

    Thank you , This structure is set based off your recommendation. I really appreciate the support on this one!  lets close the case with a happy customer!