[Appointments+] Do something with sub fields from submitted data.

When a user submits an appointment I wan't 2 functions do something with the data that the user submitted.

However I could NOT find any documentation on how to get user data for an appointment. Here is the code I wrote so far that executes after the appointment has been added to the database.

function prepareBookingSMS($app_id) {

        $email = get_post_meta($app_id,'email');
        $date = get_post_meta($app_id,'date');
        $phone = get_post_meta($app_id,'phone');

        doSomethingWithData($email,$date,$phone);

    }
    add_action('wpmudev_appointments_insert_appointment','prepareBookingSMS');

    function doSomethingWithData($email,$date,$phone){

        // Do something with data, like send it to SMS text provider!

    }

How would i go about putting the user submitted data into variables?

  • Konceptas A/S

    I don't wan't to store any data! I wanna be able to use the data already stored when someone creates a booking.

    Whenever wpmudev_appointments_insert_appointment is called I wan't an action to run that GETS the booking information such as name, date of booking, phone and e-mail and pass it to a method that does something with the data.

    However i'm unsure how you get that data from only a booking idea WHICH i can read online is the only thing that wpmudev_appointments_insert_appointment returns.

    So please take a look at this again:

    function prepareBookingSMS($app_id) {
    
            // HOW DO I FILL THESE VARS WITH DATA FROM THE BOOKING ($app_id).
           // IS get_post_meta THE RIGHT THING TO USE?
            $email = get_post_meta($app_id,'email');
            $date = get_post_meta($app_id,'date');
            $phone = get_post_meta($app_id,'phone');
    
            doSomethingWithData($email,$date,$phone);
    
    }
    add_action('wpmudev_appointments_insert_appointment','prepareBookingSMS');
    
    function doSomethingWithData($email,$date,$phone){
    
            // Do something with data, like send it to SMS text provider!
    
    }
  • Adam Czajczyk

    Hi Konceptas A/S

    Thank you for additional explanation.

    I misunderstood you at first but it's clear now.

    With "wpmudev_appointments_insert_appointment" you get appointment ID only in return so you need to fetch the data "on your own" inside the callback function.

    The plugin is using an "appointments_get_appointment($app_id)" function (which you'll find inside /includes/class--app-appointment.php file). Looking closer at this function shows that it basically is just fetching entire row from the database for the given ID.

    Assuming that you db prefix is standard "wp_", you would wan to fetch a row of ID = $app_id from "wp_app_appointments" table. Take a look into database for the structure.

    Then you can also get additional data from "wp_app_appointmentmeta" table but so far that mostly stores GDPR consent value, from what I can see. Most of the important data (such as e.g. username/ID, e-mail, service ID, worker - which is service provider - ID, start and end dates) you will fetch from that first table.

    You can actually use standard WP routines to fetch data from the table, because all you need for that is the table name and an appointment ID - which is returned by "wpmudev_appointments_insert_appointment" and which is equal to the value of ID column in that table.

    I hope that helps a bit more :wink:

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.