离开woocommerce产品评论后重定向客户 [英] Redirect customers after leaving woocommerce product review

查看:41
本文介绍了离开woocommerce产品评论后重定向客户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 woocommerce 中留下产品评论后,我试图将用户重定向到感谢页面.我知道代码

I am trying to redirect users to a thank you page after leaving a product review in woocommerce. I know the code

  add_filter('comment_post_redirect', 'redirect_after_comment');
    function redirect_after_comment($location)
    {
    return $_SERVER["HTTP_REFERER"];
    }

会将所有评论重定向到一个位置,但我似乎找不到过滤器或挂钩来仅指定 woocommerce 产品评论.以前有人这样做过吗?理想情况下,我只想重定向到标准的 wordpress 页面,以便将来可以向该页面模板文件添加选项和功能.

will redirect all comments to a location, but I can't seem to find a filter or hook to specify only woocommerce product reviews. Has anyone done this before? Ideally I would just like to redirect to a standard wordpress page so I can add options and features to that pages template file in the future.

推荐答案

comment_post_redirect 过滤器有第二个参数.这个参数是 $comment 对象,我们可以从中获取帖子的 ID.使用帖子的 ID,您可以测试 post_type 并相应地调整返回的变量.

The comment_post_redirect filter has a second parameter. This parameter is the $comment object from which we can grab the post's ID. With the post's ID you can test for post_type and adjust the returned variable accordingly.

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产品评论后重定向客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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