add_filter( 'woocommerce_product_reviews_list_table_prepare_items_args', 'structured_data_modify_product_reviews_query' );
function structured_data_modify_product_reviews_query($args) {
return wp_parse_args(get_filter_api_review_id_arguments(), $args);
}
function get_filter_api_review_id_arguments() {
$args = [];
$args['meta_query'] = [
[
'key' => 'custom_field',
'compare' => 'NOT EXISTS',
],
];
return $args;
}
class My_ReviewsListTable extends Automattic\WooCommerce\Internal\Admin\ProductReviews\ReviewsListTable {
public function get_review_count($product_id) {
$args = [
'post_type' => 'product_review',
'post_status' => 'publish',
'meta_query' => [
[
'key' => 'custom_field',
'compare' => 'NOT EXISTS',
],
],
'fields' => 'ids',
];
if($product_id) {
$args['meta_query'][] = [
'key' => '_product_id',
'value' => $product_id,
'compare' => '=',
];
}
$query = new WP_Query($args);
return $query->found_posts;
}
}
class Structured_Data_List_Table extends ReviewsListTable {
protected function get_review_count(string $status, int $product_id): int
{
$args = [
'type__in' => ['review', 'comment'],
'status' => $this->convert_status_to_query_value($status),
'post_type' => 'product',
'post_id' => $product_id,
'count' => true,
];
$args['meta_query'] = [
[
'key' => 'custom_field',
'compare' => 'NOT EXISTS',
],
];
return (int)get_comments($args);
}
}
add_filter( 'woocommerce_product_reviews_list_table', 'replace_reviews_list_table_class', 10, 2 );
function replace_reviews_list_table_class( $output, $reviews_list_table ) {
$structured_data_list_table = new Structured_Data_List_Table();
$structured_data_list_table->prepare_items();
ob_start();
?>
<div class="wrap">
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
<?php $structured_data_list_table->views(); ?>
<form id="reviews-filter" method="get">
<?php $page = isset( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : 'product-reviews'; ?>
<input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
<input type="hidden" name="post_type" value="product" />
<input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr( current_time( 'mysql', true ) ); ?>" />
<?php $structured_data_list_table->search_box( __( 'Search Reviews', 'woocommerce' ), 'reviews' ); ?>
<?php $structured_data_list_table->display(); ?>
</form>
</div>
<?php
return ob_get_clean();
}