我为我的用户设置了cookie,让他们知道他们来自哪个网站,我希望当用户联系我们时,他们的消息也会随cookie一起出现。
因此,我创建了一个新的短代码,并在邮件部分添加了它,但它直接发送短代码,而不是返回值
代码:
function my_shortcode( $atts ) {
return isset($_COOKIE[\'my_source\']) ? $_COOKIE[\'my_source\'] : \'\' ;
}
add_shortcode( \'my-source\', \'my_shortcode\' );
Message body in contact form 7 :
Name : [your-name]
Email : [your-email]
Phone : [form-tel]
My Source : [my-source]
Email I Received :
Name : Mohit Bumb
Email : [email protected]
Phone : 19191919191
My Source : [my-source]
最合适的回答,由SO网友:Sally CJ 整理而成
你应该这样做:
add_action( \'wpcf7_init\', \'custom_add_form_tag_my_source\' );
function custom_add_form_tag_my_source() {
// "my-source" is the type of the form-tag
wpcf7_add_form_tag( \'my-source\', \'custom_my_source_form_tag_handler\' );
}
function custom_my_source_form_tag_handler( $tag ) {
return isset( $_COOKIE[\'my_source\'] ) ? $_COOKIE[\'my_source\'] : \'\';
}
请参见
documentation 了解更多详细信息。
或者,您也可以尝试以下方法来解析常规短代码:
add_filter( \'wpcf7_mail_components\', function( $components ){
$components[\'body\'] = do_shortcode( $components[\'body\'] );
return $components;
} );
SO网友:lalo
使用过滤器“wpcf7\\u special\\u mail\\u tags”
在这个例子中,我的标签是“锦标赛”
/**
* A tag to be used in "Mail" section so the user receives the special tag
* [tournaments]
*/
add_filter(\'wpcf7_special_mail_tags\', \'wpcf7_tag_tournament\', 10, 3);
function wpcf7_tag_tournament($output, $name, $html)
{
$name = preg_replace(\'/^wpcf7\\./\', \'_\', $name); // for back-compat
$submission = WPCF7_Submission::get_instance();
if (! $submission) {
return $output;
}
if (\'tournaments\' == $name) {
return $submission->get_posted_data("tournaments");
}
return $output;
}
SO网友:armin
我迟到了,但在此场景中使用特殊标记
// Hook for additional special mail tag
add_filter( \'wpcf7_special_mail_tags\', \'wti_special_mail_tag\', 20, 3 );
function wti_special_mail_tag( $output, $name, $html )
{
$name = preg_replace( \'/^wpcf7\\./\', \'_\', $name );
if ( \'_my_cookie\' == $name ) {
$output = isset( $_COOKIE[\'my_source\'] ) ? $_COOKIE[\'my_source\'] : \'\';
}
return $output;
}
您可以使用
[_my_cookie]
调用其值