Last modified: April 24, 2024

Hooks and callbacks

If you need additional customization for your EasyAppointments you can add custom code that will interact with plugin and do custom tasks. There are callbacks and hooks on certain action performed by customer or admin user.

– Frontend callbacks

You can use frontend callback to add custom Javascript code to perform additional task

Customers form (standard or bootstrap)

When: On creating an appointment

There is event when customer create an appointment called easyappnewappointment. By listening on that event you can for example trigger Google analytics event. Simple example:

// example
document.addEventListener( 'easyappnewappointment', function( event ) {
    // place here code that will be executed when customer book appointment
    // ga( 'send', 'event', 'EasyAppointments', 'submit' );
}, false );

When: On selecting time slot in calendar

Event name: easyappslotselects.

// example
document.addEventListener( 'easyappslotselects', function( event ) {
    // redirect
    // event.details holds information on location, service, worker, price, time and date since EA version 3.7.2
    window.location.replace("https://wordpress.org/plugins/easy-appointments/");
}, false );

Note : This should be place inside JavaScript on that particular page.

– Backend callbacks

Ajax backend

When: When customer book appointment

There is a custom WordPress Action when customer book appointment that can be used for additional data processing. Action is called ea_new_app_from_customer. For example:

add_action( 'ea_new_app_from_customer', 'custom_callback_function', 10, 2 );

function custom_callback_function( $appointment_id, $appointment_data ) {
   // do stuff here
}

Note : Don’t edit EA plugin code directly instead create your own plugin or put it inside theme that is in use (as child theme).

Email action redirect URL

When: When customer/user click on Email action link (confirm / cancel appointment)

This custom filter allows you add custom redirect page instead of home page that is default. You must provide valid URL address. Action is called ea_confirmed_redirect_url for conformation and ea_cancel_redirect_url. For example:

add_filter( 'ea_confirmed_redirect_url', 'custom_confirm_callback_function', 10, 1 );

function custom_confirm_callback_function( $currentUrl) {
   // do stuff here
   return '';
}

add_filter( 'ea_cancel_redirect_url', 'custom_cancel_callback_function', 10, 1 );

function custom_cancel_callback_function( $currentUrl) {
   // do stuff here
   return '';
}

Note : Don’t edit EA plugin code directly instead create your own plugin or put it inside theme that is in use (as child theme).

Alter custom fields filter

There is filter called ea_form_rows that allows you to override values for custom fields.

add_filter('ea_form_rows', 'alter_custom_fields');

function alter_custom_field($fields) {
    // do stuff here
    return $fields;
}

Filter for controlling user capabilities on menu items

There is filter called when adding menu item in admin part.

add_filter('easy-appointments-user-menu-capabilities', 'custom_capabilities', 10, 2);

function custom_capabilities($default_capability, $menu_slug) {
    // do stuff here depending on user that is logged in
    return $default_capability;
}
along with menu items you need to allow particular user to make calls. In order to do that there is additional filter to use. Default capability is `manage_options`
add_filter('easy-appointments-user-ajax-capabilities', 'admin_ajax_capabilities', 10, 2);

function admin_ajax_capabilities($default_capability, $ajax_resource) {
    // do stuff here depending on user that is logged in
    // $arax_resource options are ['settings','services','locations','workers','connections', 'tools', 'reports']
    return $default_capability;
}