我无法在 functions.php 中定义的wordpress 操作上实现重定向。 操作是 wpcf7_before_send_mail ,此功能在一个特定条件下不得发送联系表单电子邮件。
add_action( 'wpcf7_before_send_mail', 'my_function' ); function my_function($wpcf7_data) { //redirect to another page }
你能帮帮我吗?我对wordpress自定义并没有做好准备。
答案 0 :(得分:0)
如果我了解您的问题,您想要中止发送邮件并重定向到某个页面?
我不是非常熟悉Contact Form 7,但我认为您应该使用wpcf7_skip_mail而不是wpcf7_before_send_mail,然后使用wp_redirect()重定向到另一个页面。所以你的代码应该是这样的:
function skip_mail($skip_mail, $contact_form) {
// Put in ur condition
if ($condition) {
// The redirect (look at the attached url)
wp_redirect($url)
// Return ture if you want to skip sending the mail.
return true;
}
// Return false if you want to send the mail.
return false;
}
add_filter('wpcf7_skip_mail', 'skip_mail', 10, 2);
我没有测试过代码,但认为它应该可行。
顺便说一下,这是使用wp_redirect with CF7.
的另一个例子答案 1 :(得分:0)
由于CF7在javascript中引入了一些事件,您可以尝试将此HTML添加到表单中:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>
在CF7 page中,您可以找到。