Automattic\WooCommerce\StoreApi\Schemas\V1
ProductBrandSchema::get_brand_review_count
Get total number of reviews for products of a brand.
Метод класса: ProductBrandSchema{}
Хуков нет.
Возвращает
int.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_brand_review_count( $term );
- $term(WP_Term) (обязательный)
- Term object.
Код ProductBrandSchema::get_brand_review_count() ProductBrandSchema::get brand review count WC 11.0.0
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;
}