联系表格7和Cookie值 [英] Contact Form 7 and cookie value

查看:79
本文介绍了联系表格7和Cookie值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Good morning, I'm using Contact Form 7 with email submission after form submission. Now i need to send by email a value that is stored into a cookie (it is a referral code). How can i do it?

推荐答案

没有任何插件,只需添加新的自定义特殊邮件标签

Without any plugin, it is very simple to achieve the same just adding a new custom Special Mail Tag:

STEP-1:在主题的函数中添加以下代码。php

STEP-1: Add below code in your theme's 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;
}

STEP-2:使用此短代码 [_ my_cookie_special_tag] 在您的邮件设置中。

STEP-2: Use this shortcode [_my_cookie_special_tag] in your Mail Setup.

这篇关于联系表格7和Cookie值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆