Okay
  Public Ticket #3215480
What is the meta to assign a customer to an agent?
Closed

Comments

  •  1
    Alexander started the conversation

    Hello, I want to know what is the meta key that a customer registration form field must have to be assigned to an agent?

    I have seen that this can be done with a predefined Sales Representative ID field, but I want to use a form of my own to the predefined one of woocommerce

    Attached files:  Captura de pantalla 2023-01-24 160803.jpg

  •  2,218
    WebWizards replied

    Hi Alexander,

    Thank you for purchasing our plugin!


    To assign a customer to an agent programmatically, you need to set the following user meta key:

    salesking_assigned_agent 


    The value of the meta key needs to be the USER ID of the agent that's assigned (For example 1234)

    The user ID is found in the URL when you edit the agent:


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

    Let me know if I can help with anything, or if you have any questions,

    Kind regards,

    Stefan



  •  1
    Alexander replied

    Thanks for your answer. It works very well.
    I have another question.
    It turns out that the ID that appears in the user edition page does not match the ID that appears in the agents dashboard, affiliate links page and, therefore, it does not work with the meta.

    How could I make it work with that ID?

    screenshots.


    Attached files:  Captura de pantalla 2023-01-25 085739.jpg
      Captura de pantalla 2023-01-25 085755.jpg

  •  2,218
    WebWizards replied

    Hmm, I see what you mean.


    What do you use for the custom form? Do you have a way to run PHP code in the form?


    Normally we are doing it like this in PHP:

    $agent = get_users(array(
        'meta_key'     => 'salesking_agentid',
        'meta_value'   => $agent_id, // this is the ID in the Agent Dashboard
        'meta_compare' => '=',
        'fields' => 'ids',
    ));
    $agent_user_id = $agent[0]; // this is the ID for the Meta Key
    update_user_meta($customer_id,'salesking_assigned_agent', $agent_user_id);
    

    We start with the agent ID in the dashboard and we get the standard user ID.