Created
March 23, 2017 13:39
-
-
Save mathiasmadsen/afd06d5380f74c080fb104ac5fd6eaea to your computer and use it in GitHub Desktop.
This file contains 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 characters
// Send copy, if radio checked – Based on http://www.motomax.de/wordpress/contact-form-7-send-copy-to-sender-with-checkbox-in-3-9-update/ | |
function check_mail_send_contactform($cf7) { | |
//get CF7's mail and posted_data objects | |
$submission = WPCF7_Submission::get_instance(); | |
if ( $submission ) { | |
$posted_data = $submission->get_posted_data(); | |
} | |
$mail = $cf7->prop( 'mail' ); | |
if(isset($posted_data['checkbox'][0])) { //if Checkbox checked | |
$mail2 = $cf7->prop( 'mail_2' ); //get CF7's mail_2 object | |
//now set sender's address to mail2's recipient | |
$mail2['recipient'] = $posted_data['your-email']; | |
$cf7->set_properties( array( 'mail_2' => $mail2 ) ); | |
} | |
return $cf7; | |
} | |
add_action('wpcf7_before_send_mail','check_mail_send_contactform'); |
This did it for me too if(isset($posted_data['contact_sendmail'][0]))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI: This still works with latest Contact Form 7 implementation (5.3) and the latest Wordpress installation (5.5.3).
Note that 'checkbox' reflects the name in the contact form (the second string), e.g.
[checkbox checkbox use_label_element "Send a copy of my email e-mail"]
I was just lazy and decided to call the checkbox field 'checkbox' whereas I can see jose-serrao used the name 'contact_sendmail'.