联系表格 7 和 cookie 值

CaT*_*ist 2 cookies wordpress

早上好,我在提交表单后使用联系表 7 和电子邮件提交。现在我需要通过电子邮件发送一个存储在 cookie 中的值(它是一个推荐代码)。我该怎么做?

Rez*_*mun 5

没有任何插件,只需添加一个新的自定义特殊邮件标签即可实现相同的目标:

第 1 步:在主题的functions.php 中添加以下代码

add_filter( 'wpcf7_special_mail_tags', 'wpcf7_my_cookie_mailtag', 10, 3 );
function wpcf7_my_cookie_mailtag( $output, $name, $html ) {
    if ( '_my_cookie_special_tag' != $name ) { // rename the tag name as your wish;
        return $output;
    }

    if ( ! $contact_form = WPCF7_ContactForm::get_current() ) {
        return $output;
    }

    $val = isset($_COOKIE['my_cookie']) ? $_COOKIE['my_cookie'] : '';

    return $html ? esc_html($val) : $val;
}
Run Code Online (Sandbox Code Playgroud)

第 2步:[_my_cookie_special_tag]在您的邮件设置中使用此简码。