Based on a radio button i need to skip/ disable sending the second mail of a contact form 7 form. I currently use the following script in my functions.php but the mail is still going out when the selection is made.
function skip_mail($cf){
$formID = $cf->id();
$wpcf7 = WPCF7_ContactForm::get_current();
$submission = WPCF7_Submission::get_instance();
if (!$submission){
return;
}
if($formID == '8573'){
$submitData = $submission->get_posted_data();
$mail = $wpcf7->prop('mail_2');
$mailBody = $mail['body'];
if($submitData['registration'][0] == 'Can not join') {
$abort = true;
} else {
$mail['body'] = $mailBody;
$wpcf7->set_properties( array("mail_2" => $mail));
}
} else {
return;
}
}
add_action('wpcf7_before_send_mail', 'skip_mail', 10, 3);
You haven't passed &$abort
to your function parameters. It's the second parameter.
function skip_mail( $cf, $abort, $submission ) {
$formID = $cf->id();
$wpcf7 = WPCF7_ContactForm::get_current();
$submission = WPCF7_Submission::get_instance();
if ( ! $submission ) {
return;
}
if ( 8573 === $formID ) {
$submitData = $submission->get_posted_data();
$mail = $wpcf7->prop( 'mail_2' );
$mailBody = $mail['body'];
if ( 'Can not join' === $submitData['registration'][0] ) {
$abort = true;
} else {
$mail['body'] = $mailBody;
$wpcf7->set_properties( array( 'mail_2' => $mail ) );
}
}
}
add_action( 'wpcf7_before_send_mail', 'skip_mail', 10, 3 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.