Skip Navigation

[Resolved] Add email address from parent post in cred notification

This support ticket is created 5 years, 8 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 9 replies, has 2 voices.

Last updated by Shane 5 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1253257

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?

#1253427

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

#1253429

I tried that as well, but still didn't work.

#1253433

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

$recipients[]

Run the function again and see if the code breaks at this point and gives the email print out.

Thanks,
Shane

#1253459

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."

#1253641

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

#1265973

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

#1265981

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

#1266003

Thanks for the update, Shane. Any fix for this issue?

#1268189

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