• I’ve tried to automatically send the comment meta field values in the notification email. It’s getting very close, but I can’t quite get it to work 100%. The code below shows the field titles, but it doesn’t get the field value, and I can’t for the life of me figure out what to do to fix it. Any help would be fantastic, please:

    // Customise comment notification email
    function custom_notificaion($notify_message, $comment_id) {
    $comment_obj = get_comment($comment_id); //Get comment object
    $comment_post = get_post($comment_obj->comment_post_ID); //Get post object
    
    $comment_meta = get_option('wpcomment_meta');
    foreach ($comment_meta as $index => $meta){
    	$comment_meta_key = $meta['data_name'];
    	$comment_meta_val = get_comment_meta($comment_id, $comment_meta_key, true);
    	$num_id = trim("$comment_id");
    	$comment_meta_val = get_comment_meta($num_id, $comment_meta_key, true);
    	if($comment_meta_val != ''){
    		$noticeText .= sprintf(__('%s '), esc_attr($meta['title']));
    		$noticeText .= sprintf(__('%s'), esc_attr($comment_meta_val)).' | ';
    	}			
    }
    
    //Check if it is your post type
    if (isset($comment_post->post_type)) {
    $noticeText .= 'New feedback on post '.$comment_obj->post_title.' << '.get_the_permalink($comment_obj->comment_post_ID);
    	$noticeText .= ' >> From: '.$comment_obj->comment_author.' | ';
    	$noticeText .= 'Feedback: '.$comment_obj->comment_content;
            return __($noticeText, 'text-domain'); //Return the custom message here
        }
        return $notify_message; //Return default message for rest of the posts
    }
    add_filter('comment_notification_text', 'custom_notificaion', 10, 2);
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Include Comment Meta Fields in Email Notification’ is closed to new replies.