Automattic\WooCommerce\Internal\Admin\ProductReviews

ReviewsCommentsOverrides::exclude_reviews_from_comments()publicWC 1.0

Excludes product reviews from showing in the comments page.

Method of the class: ReviewsCommentsOverrides{}

No Hooks.

Return

Array.

Usage

$ReviewsCommentsOverrides = new ReviewsCommentsOverrides();
$ReviewsCommentsOverrides->exclude_reviews_from_comments( $args ): array;
$args(array|mixed) (required)
WP_Comment_Query{} query args.

ReviewsCommentsOverrides::exclude_reviews_from_comments() code WC 9.6.1

public function exclude_reviews_from_comments( $args ): array {
	$screen = get_current_screen();

	// We only wish to intervene if the edit comments screen has been requested.
	if ( ! $screen instanceof WP_Screen || 'edit-comments' !== $screen->id ) {
		return $args;
	}

	if ( ! empty( $args['post_type'] ) && $args['post_type'] !== 'any' ) {
		$post_types = (array) $args['post_type'];
	} else {
		$post_types = get_post_types();
	}

	$index = array_search( 'product', $post_types );

	if ( $index !== false ) {
		unset( $post_types[ $index ] );
	}

	if ( ! is_array( $args ) ) {
		$args = [];
	}

	$args['post_type'] = $post_types;

	return $args;
}