0

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 );
vimuth
  • 5,064
  • 33
  • 79
  • 116
widkoinflm
  • 61
  • 7
  • That hook callback function gets a `$comment` parameter passed in, which I assume is a `WP_Comment` instance. That has˝ a property `comment_parent`, which will be the ID of the parent comment (or `0` if there is none.) So you would have to recursively get the parent comment instance at this point, and keep count of how many "levels" you are moving up before you reached the comment with `comment_parent = 0`. – CBroe Apr 24 '23 at 06:42

1 Answers1

0

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 );
widkoinflm
  • 61
  • 7