phpwordpresscommentsreplay

Disable reply button from depth 6 onwards comments


How to disable the reply button from 6 deep in comments? I changed the comment depth to 6 through wordpress settings, but the reply button is still there at 6 depth : enter image description here

enter image description here

I added the reply button to the WooCommerce comment using the code below :

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>';
            }
            if ( $comment->comment_approved ) {
                echo '<span class="reply">';
                    $args = array(
                        'reply_text' => 'replay',
                        'depth'      => '1',
                        'max_depth'  => '5',
                    );
                    comment_reply_link( $args );
                    wp_enqueue_script( 'comment-reply' );
                echo '</span>'; 
            }
        echo '</div>';
    }
} 
add_action( 'woocommerce_review_after_comment_text', 'customize_woocommerce_review', 10 );

Solution

  • CBroe, Thanks for your guidance. With a little effort I was able to solve the problem, I also modified some parts of my code :

    function customize_woocommerce_review() {
        global $comment, $comment_depth;
        if ( comments_open() && ( ( '0' === $comment->comment_approved && $comment_depth <= get_option( 'thread_comments_depth' ) ) || ( $comment->comment_approved && $comment_depth < get_option( 'thread_comments_depth' ) ) ) ) {
            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>';
                }
                if ( $comment->comment_approved ) {
                    echo '<span class="reply">';
                        $args = array(
                            'reply_text' => 'replay',
                            'depth'      => $comment_depth,
                            'max_depth'  => get_option( 'thread_comments_depth' ),
                        );
                        comment_reply_link( $args );
                        wp_enqueue_script( 'comment-reply' );
                    echo '</span>';
                }
            echo '</div>';
        }
    }
    add_action( 'woocommerce_review_after_comment_text', 'customize_woocommerce_review', 10 );