Tell us what you are trying to do?
I am trying to send out a notification to the author of a post 30 days after a user meta custom date field's date.
Is there any documentation that you are following?
I have been looking at all sorts to include modifying the code found here: https://toolset.com/forums/topic/cred-form-notification-email-conditional-on-generic-field/
Also, I have been looking at The CRED API https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_event_type and https://toolset.com/documentation/programmer-reference/cred-api/#cred_custom_notification_event_type_condition
I have come up with the following but cannot get it to trigger. I am a bit lost if this is possible.
=====
// After 30 days notification trigger
add_filter( 'cred_notification_event_type', 'day30_notification_type', 99, 4);
function day30_notification_type($notification, $form_id){
if ($form_id == 14 && $notification['name'] == '30 Day Notify')
return 'custom_notification_event_type';
}
// Condition for after 30 day notify trigger
add_filter('cred_custom_notification_event_type_condition', 'day30_notification', 99, 4);
function day30_notification($condition_status, $notification, $form_id, $post_id) {
if ($form_id == 14 && $notification['name'] == '30 Day Notify') {
$date_purchase30 = get_the_author_meta( 'wpcf-date-of-home-purchase', $author_id);
$expired_date30 = date(strtotime('+31 days', $date_purchase30));
$expired_convert_date30 = date('m-d-Y', $expire_date30);
$current_date = date('m-d-Y');
if( strtotime($current_date) == $expired_convert_date30)
$condition_status = true;
}
return $condition_status;
}
===
Hello,
There are some mistakes in your custom PHP codes, this line:
$date_purchase30 = get_the_author_meta( 'wpcf-date-of-home-purchase', $author_id);
You did not set the parameter $author_id first.
Please try to add one line above it, for example:
$author_id = get_post_field( 'post_author', $post_id ); // add this line to setup $author_id parameter
$date_purchase30 = get_the_author_meta( 'wpcf-date-of-home-purchase', $author_id);
More help:
https://developer.wordpress.org/reference/functions/get_post_field/
Making that adjustment and trying it out. Thank you for the catch.
Please update here if you need more assistance for it.
Still trying to get this to trigger properly. We have not had a successful email sent out yet.
We are using the code above with the adjustment. We have our Cred form notification set up under the name "30 Day Notify" as shown in the code above. Is there any particular setup/setting/condition needed for the cred notification itself on the CRED form page?
To avoid more misunderstandings, please elaborate the question with more details:
send out a notification to the author of a post 30 days after a user meta custom date field's date.
For example, the author's user meta field "date-of-home-purchase", value is 2021-10-09, you are going to send the email notifications on: current date is more than 2022-01-09?
Please confirm it, I need to test it in my localhost, thanks