Add a couple of new hooks

Issue #1178 resolved
Valentina R created an issue

We’ve been using WooCommerce Appointments for a few years now, and have done some modifications to it (e.g. supporting subscriptions for recurring appointments, sending additional reminder emails, sending custom Google Calendar event invites to assistants, etc)

In order to do that, we’ve had to add some hooks to the original plugin of yours.

The problem with this, as you might imagine, is that we now have to edit the plugin with each new version if we want to stay up to date, and re-apply our customizations.

I wanted to ask you if you could please add just a few one-liner hooks to some parts of the plugin. It would not only simplify updates, but maybe allow other people to create more powerful extensions for your great plugin :)

Here are the things I’m suggesting to add (Happy to send a pull request if there’s a repository that can be accessed, or provide you with access to my modified plugin version)

– Add a hook to WC_Appointment->save, so we can trigger other events when an appointment is saved (e.g. CRM Automations, Different Emails, tracking, etc) (woocommerce-appointments/includes/data-objects/class-wc-appointment.php around line 225)
example:
do_action( ‘woocommerce_after_’ . $this->object_type . ‘_object_save’, $this, $this->data_store, $get_changes );

– Add hook to WC_Appointment->maybe_schedule_event, to trigger other events (e.g. calendar automations) (woocommerce-appointments/includes/data-objects/class-wc-appointment.php around line 1668)
example:
do_action( ‘woocommerce_appointment_maybe_schedule_event’, $this, $type );

– Add a hook to WC_Appointments_Cache::clear_cron_hooks (woocommerce-appointments/includes/class-wc-appointments-cache.php around line 124) & WC_Appointment_Order_Manager->clear_cron_hooks, around line 899), so we can trigger other events externally, like cleaning hooks that have been set when saving an appointment in the previous suggested hook for sending emails, and others
example:
do_action( ‘woocommerce_appointment_clear_cron_hooks’, $post_id );

– Add a filter to WC_Appointment_Order_Manager->delete_post (for skipping lines 728-734) & WC_Appointment_Order_Manager->trash_post (for skipping lines 770-777). This is important for cases like subscriptions for recurring appointments, where deleting an appointment doesn’t mean that the order should be deleted.

– Adding filters to WC_Appointment_Order_Manager->maybe_update_order, to skip the “$order->update_status( $status );” on lines 1060 & 1078, for similar uses

Note: All the lines references are made on version 4.24.0, which is the latest one at the time.


Requested here.

Comments (4)

  1. Valentina R reporter

    from customer:

    Thank you SO SO much to you and the team for taking the time :)

    The only one that wasn’t included was the last one, which since sometimes an order with cancelled appointments might not need to be cancelled (e.g. in a subscription, if the customer cancelled all their appointments for that month, we are still billing, just for $0)

    Perhaps a single filter to exit/bypass “WC_Appointment_Order_Manager->maybe_update_order” altogether, will be the simplest way?

    No rush, of course, just thought it was mentioning since that’s the only one left and will mean we don’t need to manually edit the plugin on each update anymore.

    Thanks, a million!

  2. Željan Topić

    All filters were added, the last one is called 'woocommerce_appointments_stop_order_update'. Reopen if there is something else missing.

  3. Log in to comment