Skip Navigation

[Resolved] Send notification to user based on custom date field

This support ticket is created 4 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 16 replies, has 2 voices.

Last updated by jayesonE 4 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1879023

OK, private message box enabled again.
And also point out the problem page URL and form URL, where I can edit your custom PHP codes

#1879805

My issue is resolved now. Thank you!
I was able to figure out how to make it work based on your initial suggestions.
I found this script which pretty well summed up what you were saying
hidden link

I decided not to incorporate the toolset event notification because when a users updates their profile contact date it would be in the next year or more. So I just need something that checks for any upcoming renewals once a day.

For the query part of the above script I used this.
function db_renewal() {

//
$before_date = date( "U", strtotime( "+14days" ) ); // I need to find a better way to check this.
$before_date_plus1 = date( "U", strtotime( "+15days" ) );
global $wpdb;

$results = $wpdb->get_results( "
SELECT user_id, meta_value as 'wpcf-contract-end-date'. // Toolset custom field
FROM $wpdb->usermeta
WHERE `meta_key` = 'wpcf-contract-end-date' AND `meta_value` > $before_date AND `meta_value` < $before_date_plus1" ); // Need to find a better way to compare

foreach ($results as $results) { // Sends an email for each result.

wp_mail( get_option( 'admin_email' ), $subject, $body ); // Still working on how to send to each user
}

}

add_action( 'db_renewal', 'db_renewal' );