Okay
  Public Ticket #3582013
Development hook
Closed

Comments

  • Liberty Painting started the conversation

    Hi,

    We are looking to pass additional details upon user create new appointment. Purpose of this is to pass some marketing metrics. I noted there is a field for internal note and I would like to pass data to that field.

    As per documentation I tried following hook but it not working. As there is no any example or clear detail mentioned in that documentation it hard t figure out what  it returns.


    function example_callback( $data ) {
    $data['internalNotes'] = "Testing";
    return $data; 

    add_filter( 'AmeliaAppointmentBookingAddedFilter', 'example_callback', 10, 1 );



    I would like to get to know what is the best method and example code of it detailing with clear comments.

  •  410
    Stefan replied

    Hello Liberty Painting,

    Thanks for reaching out to us.

    Here is the script that you can try 

    function my_custom_function($data) {
        $container = require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
        $customer = $data['bookings'][0]['customer'];
        // 'test test' is field value
        // 'note' is column name
        $container['domain.users.customers.repository']->updateFieldById($customer['id'], 'test test', 'note');
        return $data;
    }
    add_filter('AmeliaAppointmentBookingAddedFilter', 'my_custom_function', 10, 1);

    Custom code needs to be applied to the page where the booking form is. Depending on what you're using (Gutenberg blocks, or some page builder), adding the CSS or JS can be done in a few different ways. 

    If you need help with adding custom JS to the page, please take a look at this article.

    Let us know if it works.








    Kind Regards, 

    Stefan Petrov
    [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

  • Liberty Painting replied

    Hi Stefan,

    Hope you well and thank you for prompt response. I have applied the code you given in functions.php file but it not works. after I book new appointment I checked the appointment internal notes but it still empty. I'm not sure what part I wronged here. Can you please help me.


    Thank You.


  •  410
    Stefan replied

    Hello Liberty Painting,

    Apologies for the confusion, there was a misunderstanding. This script is for adding a customer note. You can try using this one instead 

    function my_custom_function($data) {
        $container = require AMELIA_PATH . '/src/Infrastructure/ContainerConfig/container.php';
        $appointment = $data['appointment'];
        // 'test test' is field value
        // 'internalNotes' is column name
        $container['domain.booking.appointment.repository']->updateFieldById($appointment['id'], 'test test', 'internalNotes');
        return $data;
    }
    add_filter('AmeliaAppointmentBookingAddedFilter', 'my_custom_function', 10, 1);

    Also, I've said that you need to add this as the JavaScript hook, but i see that you've already added it to the functions.php, and that is correct. Apologies for that.

    It should be working now, please let us know.



    Kind Regards, 

    Stefan Petrov
    [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