Skip Navigation

[Closed] Trigger CRED Notification based on User Meta Date Field

This support ticket is created 3 years 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)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2213177

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;
}

===

#2213493

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/

#2213957

Making that adjustment and trying it out. Thank you for the catch.

#2215393

Please update here if you need more assistance for it.

#2216125

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?

#2216445

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

The topic ‘[Closed] Trigger CRED Notification based on User Meta Date Field’ is closed to new replies.