* @link https://gitlab.com/snippets/1662384 * * @param \WPCF7_ContactForm $contactForm */ function filterContactFormRecipient($contactForm) { // Get the post id from the existing WPCT7 special mail tags. $postID = \wpcf7_special_mail_tag('', '_post_id', ''); // Get the desired post meta. $emailAddress = get_post_meta($postID, 'company_email', true); // Get the submited form email data. $mailData = $contactForm->prop('mail'); // Change the 'recipient' (or any other field). $mailData['recipient'] = $emailAddress; // Update/set the form properties. $contactForm->set_properties(['mail' => $mailData]); } add_action('wpcf7_before_send_mail', __NAMESPACE__ . '\\filterContactFormRecipient');