I have a function which sends an email when a task is completed
function complete_task($id)
{
wp_mail('abc@mail.com','test subject', 'test message');
}
Now I want to change this as when a specific task with the ID is completed then it should not send an email instead of registring a schedule event. I have done this with wp_schedule_single_event
my code for this is below:
function complete_task($id)
{
if($id!=3) // 3 is any ID
{
wp_mail('abc@mail.com','test subject', 'test message');
}
else
{
add_action( 'send_single_email_event', 'do_this_in_after_1_hour', 10, 3 );
}
}
I have added the add_action
hook in else
section because in codex
there is written to add this in a function you can check it here
Schedule an event one hour from now
// function for sending schedule event
function do_this_in_after_1_hour()
{
wp_mail( 'abc@mail.com', 'test subject', 'test message');
}
// singdle schedule event
wp_schedule_single_event(time() + 3600, 'send_single_email_event');
its not working, mean not sending email.