mathiasmadsen
3/23/2017 - 1:39 PM

Send a copy if radio is checked

// 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');