Automattic\WooCommerce\StoreApi\Schemas\V1
ProductBrandSchema::get_brand_review_count
Get total number of reviews for products of a brand.
Method of the class: ProductBrandSchema{}
No Hooks.
Returns
Int
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_brand_review_count( $term );
- $term(WP_Term) (required)
- Term object.
ProductBrandSchema::get_brand_review_count() ProductBrandSchema::get brand review count code WC 9.9.4
protected function get_brand_review_count( $term ) { global $wpdb; $children = get_term_children( $term->term_id, 'product_brand' ); if ( ! $children || is_wp_error( $children ) ) { $terms_to_count_str = absint( $term->term_id ); } else { $terms_to_count = array_unique( array_map( 'absint', array_merge( array( $term->term_id ), $children ) ) ); $terms_to_count_str = implode( ',', $terms_to_count ); } $products_of_brand_sql = " SELECT SUM(comment_count) as review_count FROM {$wpdb->posts} AS posts INNER JOIN {$wpdb->term_relationships} AS term_relationships ON posts.ID = term_relationships.object_id WHERE term_relationships.term_taxonomy_id IN (" . esc_sql( $terms_to_count_str ) . ') '; $review_count = $wpdb->get_var( $products_of_brand_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared return (int) $review_count; }