Skip to content

Instantly share code, notes, and snippets.

@rafiahmedd
Last active August 4, 2021 22:20
Show Gist options
  • Save rafiahmedd/5134944f56c44a3ec344794e48926118 to your computer and use it in GitHub Desktop.
Save rafiahmedd/5134944f56c44a3ec344794e48926118 to your computer and use it in GitHub Desktop.
Send hourly email to the users who don't pay the total yet.
//Send Email To unpaid/pending users via cron job wp (FF payment status = pending)
/**
* this method will register event to WordPress init
*/
add_action( 'init', 'sendEmailToPaymentPendingUsers');
function sendEmailToPaymentPendingUsers(){
if( !wp_next_scheduled( 'notify_unpaid_users' ) ) {
// schedule an event
//Available Event Types (hourly, twicedaily, daily, weekly, fifteendays, monthly)
wp_schedule_event( time(), 'hourly', 'notify_unpaid_users' );
}
}
add_action( 'notify_unpaid_users', 'sendEmailToUnpaidUsers' );
/**
* this method will call when cron executes
*/
function sendEmailToUnpaidUsers() {
/**
*$formId = 14 please replace the 14 with your form ID
**/
$formApi = fluentFormApi('forms')->entryInstance($formId = 14);
$entries = $formApi->entries();
$count = count($entries);
$subject = 'Please Pay';
$message = 'Hi, <br> Please pay the total.';
$send_email_to = array();
for ($i=0; $i<$count; $i++) {
if($entries['data'][$i]->payment_status === 'pending'){
$send_email_to[] =$entries['data'][$i]->response['email'];
}
}
wp_mail($send_email_to, $subject, $message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment