简体   繁体   English

联系表格 7 - 跳过发送第二封邮件

[英]Contact Form 7 - skip sending second mail

Based on a radio button i need to skip/ disable sending the second mail of a contact form 7 form.基于单选按钮,我需要跳过/禁用发送联系表格 7 表格的第二封邮件。 I currently use the following script in my functions.php but the mail is still going out when the selection is made.我目前在我的函数中使用以下脚本。php 但在进行选择时邮件仍在发送。

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.您尚未将&$abort传递给您的 function 参数。 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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM