You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用WooCommerce评论层级达6级时的回复按钮?

解决WooCommerce 6级评论仍显示回复按钮的问题

你需要在现有代码中增加当前评论层级的判断,同时修正comment_reply_link的max_depth参数,使其和你WordPress后台设置的6级保持一致。具体修改如下:

修改后的完整代码

function customize_woocommerce_review() {
    global $comment;
    if ( comments_open() ) {
        echo '<div class="footer">';
            if ( '0' === $comment->comment_approved ) {
                echo '<em class="woocommerce-review__awaiting-approval">';
                    esc_html_e( 'Your review is awaiting approval', 'woocommerce' );
                echo '</em>';
            }
            // 新增评论层级判断:仅当前层级小于6时显示回复按钮
            if ( $comment->comment_approved && $comment->comment_depth < 6 ) {
                echo '<span class="reply">';
                    $args = array(
                        'reply_text' => 'replay',
                        'depth'      => '1',
                        'max_depth'  => '6', // 改为和后台设置一致的6级
                    );
                    comment_reply_link( $args );
                    wp_enqueue_script( 'comment-reply' );
                echo '</span>'; 
            }
        echo '</div>';
    }
} 
add_action( 'woocommerce_review_after_comment_text', 'customize_woocommerce_review', 10 );

关键修改点说明

  • 新增层级判断:在输出回复按钮的条件中加入$comment->comment_depth < 6,这样当评论已经是第6级时,就不会渲染回复按钮。
  • 修正max_depth参数:把原来的max_depth => '5'改成'6',确保和你WordPress后台设置的评论最大层级匹配,避免逻辑冲突。

修改后,第6级的评论就不会再显示回复按钮了,符合你的需求。

内容的提问来源于stack exchange,提问作者widkoinflm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 23:40:04