I am following the instruction on this post:
https://toolset.com/forums/topic/cred-notification-to-email-from-parent-post-field-no-longer-working-after-types-3-0-update/
I've tried everything, but I can't get the form to pull the email address from the parent post type into the CC field.
Here's the code i'm using:
add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
// Check notification name matches target notification
if ( isset($notification['name']) && 'Send Email of Visit Details' == $notification['name'] ) {
// Add a CC to contact email address
$parent_id = toolset_get_parent_post_by_type( $post_id, 'program' );
$email_of_organizer = get_post_meta($parent_id, 'wpcf-contact-email-address', true);
$recipients[] = array(
'to' => 'cc',
'address' => '$email_of_organizer',
'name' => '',
'lastname' => ''
);
}
return $recipients;
}
When I replace the $email_of_organizer with an actual email address, it works. But the $email_of_organizer variable doesn't seem to work.
Can you help?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amin,
Thank you for contacting our support forum.
Assuming that $email_of_organizer is storing the correct value then it should be added like this.
'address' => $email_of_organizer ,
Without the quotations.
Thanks,
Shane
I tried that as well, but still didn't work.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amin,
Lets checked if the correct data is being passed,
Could you add this
die('this is the email'.$email_of_organizer);
Add this right before this line
Run the function again and see if the code breaks at this point and gives the email print out.
Thanks,
Shane
I added the code. The email didn't get triggered this time.
I don't know what you mean by "gives the email print out."
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amin,
Would you mind allowing me to have access to the site as well as the area where you are testing this ?
The problem I suspect is that the correct email is not being retrieved by the code.
What I need to do is check the code line by line to see if the correct parameters are being passed.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amin,
Thank you for the credentials.
I started having a look at this for you but it will take some more time to debug.
The good thing is your notifications are being sent just that the hook is not firing.
I'm still looking into this.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amin,
Just an update, the hook is working when i manually add my email to it.
So i'm confirming the hook works, however the issue seems to be where its getting the parent post type information.
Thanks,
Shane
Thanks for the update, Shane. Any fix for this issue?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amin,
I've got good news.
This is now resolved.
The fix was to use this line of code.
$parent_id = toolset_get_related_post( $post_id, 'program-visit' );
So the complete code is
// send email notification to program contact
add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
// Check notification name matches target notification
if ( isset($notification['name']) && 'Send Email of Visit Details' == $notification['name'] ) {
// Add a CC to contact email address
$parent_id = toolset_get_related_post( $post_id, 'program-visit' );
$email_of_organizer = get_post_meta($parent_id, 'wpcf-contact-email-address', true);
$recipients[] = array(
'to' => 'cc',
'address' => $email_of_organizer,
'name' => '',
'lastname' => ''
);
}
return $recipients;
}
Thanks,
Shane