Automattic\WooCommerce\Internal\Admin\ProductReviews

ReviewsUtil::comments_clauses_without_product_reviewspublic staticWC 1.0

Removes product reviews from the edit-comments page to fix the "Mine" tab counter.

Method of the class: ReviewsUtil{}

No Hooks.

Returns

Array|Mixed.

Usage

$result = ReviewsUtil::comments_clauses_without_product_reviews( $clauses, $comment_query );
$clauses(array|mixed) (required)
A compacted array of comment query clauses.
$comment_query(WP_Comment_Query) (required)
The WP_Comment_Query instance being filtered.

ReviewsUtil::comments_clauses_without_product_reviews() code WC 10.3.3

public static function comments_clauses_without_product_reviews( $clauses, $comment_query ) {
	global $wpdb;

	if ( ! empty( $comment_query->query_vars['post_type'] ) ) {
		$post_type = $comment_query->query_vars['post_type'];
		if ( ! is_array( $post_type ) ) {
			$post_type = explode( ',', $post_type );
		}
		if ( in_array( 'product', $post_type, true ) ) {
			return $clauses;
		}
	}

	/**
	 * Any comment queries with these values are likely to be custom handling where we don't want to change default behavior.
	 * This may change for the `type` query vars in the future if we break out review replies as their own type.
	 */
	foreach ( array( 'ID', 'parent', 'parent__in', 'post_author__in', 'post_author', 'post_name', 'type', 'type__in', 'type__not_in', 'post_type__in', 'comment__in', 'comment__not_in' ) as $arg ) {
		if ( ! empty( $comment_query->query_vars[ $arg ] ) ) {
			return $clauses;
		}
	}

	if ( ! empty( $comment_query->query_vars['post_id'] ) && absint( $comment_query->query_vars['post_id'] ) > 0 ) {
		if ( 'product' === get_post_type( absint( $comment_query->query_vars['post_id'] ) ) ) {
			return $clauses;
		}
	}

	if ( ! empty( $comment_query->query_vars['post__in'] ) ) {
		$post_ids = wp_parse_id_list( $comment_query->query_vars['post__in'] );
		_prime_post_caches( $post_ids, false, false );
		foreach ( $post_ids as $post_id ) {
			if ( 'product' === get_post_type( $post_id ) ) {
				return $clauses;
			}
		}
	}

	$clauses['join']  .= " LEFT JOIN {$wpdb->posts} AS wp_posts_to_exclude_reviews ON comment_post_ID = wp_posts_to_exclude_reviews.ID ";
	$clauses['where'] .= ( trim( $clauses['where'] ) ? ' AND ' : '' ) . " wp_posts_to_exclude_reviews.post_type NOT IN ('product') ";

	return $clauses;
}