离开 woocommerce 产品评论后重定向客户
Redirect customers after leaving woocommerce product review
我试图在 woocommerce 中留下产品评论后将用户重定向到感谢页面。我知道密码
add_filter('comment_post_redirect', 'redirect_after_comment');
function redirect_after_comment($location)
{
return $_SERVER["HTTP_REFERER"];
}
会将所有评论重定向到一个位置,但我似乎找不到过滤器或挂钩来仅指定 woocommerce 产品评论。有没有人这样做过?理想情况下,我只想重定向到一个标准的 wordpress 页面,这样我就可以在将来向该页面模板文件添加选项和功能。
comment_post_redirect
过滤器有第二个参数。此参数是 $comment
对象,我们可以从中获取 post 的 ID。使用 post 的 ID,您可以测试 post_type
并相应地调整返回的变量。
add_filter( 'comment_post_redirect', 'redirect_after_comment', 10, 2 );
function redirect_after_comment( $location, $comment ){
$post_id = $comment->comment_post_ID;
// product-only comment redirects
if( 'product' == get_post_type( $post_id ) ){
$location = 'http://www.woothemes.com';
}
return $location;
}
我试图在 woocommerce 中留下产品评论后将用户重定向到感谢页面。我知道密码
add_filter('comment_post_redirect', 'redirect_after_comment');
function redirect_after_comment($location)
{
return $_SERVER["HTTP_REFERER"];
}
会将所有评论重定向到一个位置,但我似乎找不到过滤器或挂钩来仅指定 woocommerce 产品评论。有没有人这样做过?理想情况下,我只想重定向到一个标准的 wordpress 页面,这样我就可以在将来向该页面模板文件添加选项和功能。
comment_post_redirect
过滤器有第二个参数。此参数是 $comment
对象,我们可以从中获取 post 的 ID。使用 post 的 ID,您可以测试 post_type
并相应地调整返回的变量。
add_filter( 'comment_post_redirect', 'redirect_after_comment', 10, 2 );
function redirect_after_comment( $location, $comment ){
$post_id = $comment->comment_post_ID;
// product-only comment redirects
if( 'product' == get_post_type( $post_id ) ){
$location = 'http://www.woothemes.com';
}
return $location;
}