Forked from jose-serrao/WPCF7 - Send copy to sender with checkbox
Created
July 4, 2019 08:03
-
-
Save khripunovpp/d103201e0fd03ed7892c05643b008678 to your computer and use it in GitHub Desktop.
WPCF7 - Send copy to sender with checkbox (Kudos to http://www.motomax.de/wordpress/contact-form-7-send-copy-to-sender-with-checkbox-in-3-9-update/ and https://gist.github.com/mathiasmadsen/afd06d5380f74c080fb104ac5fd6eaea)
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
1. Open the CF7 contact form which you want to edit in wordpress Admin area. You set up the [checkbox] snippet which produces the checkbox in the contact form on your website: | |
[checkbox contact_sendmail "Send me a copy of this message"] | |
2. Activate Mail(2) | |
3. Add to functions.php | |
function check_mail_send_contactform($cf7) | |
{ | |
$submission = WPCF7_Submission::get_instance(); | |
if ( $submission ) | |
{ | |
$posted_data = $submission->get_posted_data(); | |
} | |
$mail = $cf7->prop( 'mail' ); | |
if(!empty($posted_data['contact_sendmail'][0])) | |
{ | |
$mail2 = $cf7->prop( 'mail_2' ); | |
$mail2['recipient'] = $posted_data['your-email']; | |
$cf7->set_properties( array( 'mail_2' => $mail2 ) ); | |
} | |
else { | |
$cf7->set_properties( array( 'mail_2' => array() )); | |
} | |
return $cf7; | |
} | |
add_action('wpcf7_before_send_mail','check_mail_send_contactform'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment