Appointments + hook/action Service Provider Removed

Hi,

I am looking for a hook/action that I can use run my function after an Appointments + Service Provider is deleted from Appointments +. Unlike when services are deleted from Appointments + and the action hook
do_action('app-services-before_save'); //line 5561 Appointments + version 1.4.6
is run. Is there a similar do_action('app-service-provider-before_save')?

Otherwise any suggestion on how I can hook onto a service provider delete event from Appointments +?

Thank you,

Tin

  • Michelle Shull
    • DEV MAN’s Apprentice

    Hi, Tin!

    This is a bit above my paygrade, so I'm going to refer you to our second line team. Keep in mind, sometimes it can take a little longer to hear back from them, as they handle a lot of complex and code-related topics here on the forum, so they may take a bit longer to respond than a first line response.

    Thanks for your question, I'll be following this thread closely!

  • Vinod Dalvi
    • WP Unicorn

    Hi Tin,

    Thank you for your patience.

    You can use the following action hook defined in the Appointments+ plugin file appointments.php on line number 5701

    do_action('app-workers-worker-updated', $ID);

    The id in the above code is the service provider id.

    Please advise if you have more questions.

    Best Regards,
    Vinod Dalvi

  • hoangker
    • Site Builder, Child of Zeus

    Hi Vinod,

    thanks for your reply, I have noticed that the do_action that you mentioned above is being called, but the reason why I didn't hook onto this was because it only gets fired when you have updated a service provider, not deleted the service provider. Line number 5701 is not reached by appointments + when you delete a user since the if condition on line 5620 appointments.php prevents this because when you want to delete a service provider you have to uncheck all the services they provide which leads to an empty ($worker['services_provided']) array.

    if ( $ID && !empty ( $worker["services_provided"] ) ) {//Line 5620
                ...
                do_action('app-workers-worker-updated', $ID);//Line 5701
               ...
      } else {
               //delete service provider code is in this else block.
              //we need a do_action here to hook onto when a service provider deleted.
      }

    In the above code is there anyway we can add a hook in the else block?
    Thanks,

    Tin

  • Vinod Dalvi
    • WP Unicorn

    Hi Tin,

    Thank you for your patience.

    I can see the hook app-workers-worker-updated is executed on deleting the service provider when there are more than one service providers but it doesn't execute when there are only a single service provider and also using this week we can't get information about the service provider that is being deleted.

    To overcome these limitations, you can use the following code in the functions.php file of your child theme.

    add_action('admin_init', 'save_custom_worker');
    function save_custom_worker(){
    	if ( isset($_POST["action_app"]) && 'save_workers' == $_POST["action_app"] && is_array( $_POST["workers"] ) ) {
    		foreach ( $_POST["workers"] as $worker ) {
    				if ( empty ( $worker["services_provided"] ) ) {
    						echo "The service provider having user ID ". $worker['user'] ." is deleted.";
    						// Add your custom code here which you want to execute on deleting service provider.
    				}
    		}
    	}
    }

    Regards,
    Vinod Dalvi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.