Okay
  Public Ticket #4522309
Auto Role Assignment When Adding Customers Through SalesKing
Closed

Comments

  • Marcus started the conversation

    Hi Team,

    Hope you’re doing well. I have a quick question regarding customer role assignment.

    When a new customer is added through the “My Customers” section in the SalesKing agent dashboard, the system currently assigns the default WooCommerce role Customer.

    Is it possible to automatically assign a different role instead—for example, Referred Customer—whenever a customer is created from this interface?

    Appreciate your guidance on whether this can be configured natively or if a custom hook is required.

    Thank you!

    Attached files:  Screenshot 2025-12-03 at 12.08.20 AM.png

  •  2,619
    WebWizards replied

    Hi Marcus,

    Glad to assist,

    There is no native setting to change the default role specifically for customers added by agents, but you can achieve this using a code snippet.

    We have a hook called salesking_after_customer_created that runs immediately after the agent creates the user. You can use this to force a specific role for those users.

     

    Here is an example snippet that assigns a "Referred Customer" role:

    add_action('salesking_after_customer_created', function($user_id){
    
        $user = new WP_User($user_id); // Replace 'referred_customer' with the actual slug of your custom role 
    
        $user->set_role('referred_customer'); 
    
    }, 10, 1);

    You can add this to your child theme's functions.php file or by using a code snippets plugin. Please make sure to update referred_customer in the code to match the actual slug of the role you created.

     

    Kind regards,
    Stefan

  • Marcus replied

    Thanks Stefan,

    You have been very helpful! Appreciate that.

    Regards, 

    Marcus

  •  2,619
    WebWizards replied

    You're very welcome! Happy to help.

    If you run into any other questions or issues, feel free to reach out anytime.

    Kind regards,
    Stefan