Last active
April 24, 2018 20:10
-
-
Save apintocr/ba28dc266750910b5e7a039629e8e6a5 to your computer and use it in GitHub Desktop.
Revisions
-
apintocr revised this gist
May 17, 2017 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,7 @@ * You can add some conditional checks to make sure the data is correct. * * @author António Pinto <[email protected]> * @link https://gitlab.com/snippets/1662384 * * @param \WPCF7_ContactForm $contactForm */ -
apintocr created this gist
May 17, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ <?php /** * Contact Form 7 - Conditionally Chance Recipient to Post Meta * * This function gets the current post id and grabs the desired meta to use * it on the submited form data to change the recipient email conditionally. * You can add some conditional checks to make sure the data is correct. * * @author António Pinto <[email protected]> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @ref 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');