Okay
  Public Ticket #2739915
Customer creation function
Closed

Comments

  •  2
    Alexander T Martins started the conversation

    Is there a function I can use to create the Amelia Customer?

    If so, I can add it manually as an action after the user registers on the website.



    Thank you

  •  2,503
    Aleksandar replied

    Hello Alexander

    Amelia Customer is created when the customer books an appointment or an event from front-end.

    If you want them to also have the "Amelia Customer" WordPress user, you can enable "Automatically create Amelia Customer user" in Amelia Settings/Roles/Customer.

    At the moment, there's no way to automatically create a customer without them booking the appointment.

    JS files are modified (minimized) in the public version of the plugin (in our development environment is accessible), but unfortunately, I can not send you our source code because that is the policy of our company.

    All those files that have extension .vue are compressed and minimized in JS files that are very hard and not recommended modifying. So in order to add some other features, you can unminify the js and customize it.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •   Alexander T Martins replied privately
  •  2,503
    Aleksandar replied

    Hello Alexander.

    To create the user when someone registers on your website, without booking an appointment, you can try this:

    add_action( 'user_register', 'custom_amelia_registration_save', 10, 1 );
    function custom_amelia_registration_save($user_id) {
        global $wpdb;
        $wpUser = get_user_by('ID', $user_id);
        $ameliaUserId = $wpdb->get_col(
            "SELECT id FROM wp_amelia_users WHERE email = '{$wpUser->user_email}'"
        );
        if (!$ameliaUserId && in_array('wpamelia-customer', $wpUser->roles)) {
            $ameliaUserFirstName = $wpUser->user_first_name ?: $wpUser->user_nicename;
            $ameliaUserLastName = $wpUser->user_last_name ?: $wpUser->user_nicename;
            $wpdb->query("
                INSERT INTO wp_amelia_users
                (
                type,
                status,
                externalId,
                firstName,
                lastName,
                email
                ) VALUES (
                'customer',
                'visible',
                {$user_id},
                '{$ameliaUserFirstName}',
                '{$ameliaUserLastName}',
                '{$wpUser->user_email}'
                )
            ");
        }

    So, when a WP user is created, if that email doesn't already exist in our database table, and if that user role is "wpamelia-customer", the Amelia user will be created in our table also.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Jeffery Powers replied

    This worked well for me when placed in the functions.php of the theme. 

    Thank you. 

    Also I think your values for $wpUser should be user_firstname and user_lastname and user_first_name and not user_first_name and user_last_name else the user_nicename defaults in each case.

  •  2,503
    Aleksandar replied

    Thanks for letting me know that it worked, Jeffery.

    I'll forward your suggestion to our development team, so they can think about it for the future.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Christian Graf replied

    Hallo support team,

    I have exactly the same need. The code below does not work for me, has anything changed in the meantime? Or do you have another hint for me?

    Thanks,
    Christian

  • Christian Graf replied

    I found the solution! I had to adopt the table-prefix. wp_amelia_users uses the generic table-prefix, changing this to xyzwhatever_amelia_users did the job. This is twice in the code. I also tweaked the username lines a bit. user_firstname and user_lastname are a bit old – property names used in WordPress prior to version 2.0.0 (14 years ago ...) – (user_first_name and user_last_name from the original code-suggestion was wrong at all) and I replaced it with first_name and last_name. So here is the whole working code for the functions.php:

    /* ==========================================================================
     * #create the user when someone registers on your website, without booking an appointment
    ============================================================================*/
    add_action( 'user_register', 'custom_amelia_registration_save', 10, 1 );
    function custom_amelia_registration_save($user_id) {
        global $wpdb;
        $wpUser = get_user_by('ID', $user_id);
        $ameliaUserId = $wpdb->get_col(
            "SELECT id FROM xyzprefix_amelia_users WHERE email = '{$wpUser->user_email}'"
        );
        if (!$ameliaUserId && in_array('wpamelia-customer', $wpUser->roles)) {
            $ameliaUserFirstName = $wpUser->first_name ?: $wpUser->user_nicename;
            $ameliaUserLastName = $wpUser->last_name ?: $wpUser->user_nicename;
            $wpdb->query("
                INSERT INTO xyzprefix_amelia_users
                (
                type,
                status,
                externalId,
                firstName,
                lastName,
                email
                ) VALUES (
                'customer',
                'visible',
                {$user_id},
                '{$ameliaUserFirstName}',
                '{$ameliaUserLastName}',
                '{$wpUser->user_email}'
                )
            ");
        }

    If anyone could add an extention to check if the user is email-approved (by eg. help of Ultimate Member Plugin) – that would be a great extension!

    Thanks
    Christian

  •  1,191
    Uroš replied

    Hello Christian,

    Thank you for reaching out to us.

    Glad to hear that you found the solution and for sharing it with other users that would potentially need it.

    Also, thank you for the suggestion on the last point that you mentioned in your query, we appreciate it.

    Please let us know if you have any other questions.


    Kind Regards, 

    Uros Jovanovic
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Kassyaaf replied

    Hi, im also like to use this configuration. But when i tried insert the coding into the functions.php is seem doesnt work at all. Can anyone help me ?

    Thanks

  •  1,191
    Uroš replied

    Hello Kassyaaf,

    Have you followed the complete solution that Cristian provided in his reply?

    Looking forward to your reply.


    Kind Regards, 

    Uros Jovanovic
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables