wc_update_product_lookup_tables_rating_count()WC 3.6.0

Populate rating count lookup table data for products.

No Hooks.

Return

null. Nothing (null).

Usage

wc_update_product_lookup_tables_rating_count( $rows );
$rows(array) (required)
Rows of rating counts to update in lookup table.

Changelog

Since 3.6.0 Introduced.

wc_update_product_lookup_tables_rating_count() code WC 8.6.1

function wc_update_product_lookup_tables_rating_count( $rows ) {
	if ( ! $rows || ! is_array( $rows ) ) {
		return;
	}
	global $wpdb;

	foreach ( $rows as $row ) {
		$count = array_sum( (array) maybe_unserialize( $row['meta_value'] ) );
		$wpdb->update(
			$wpdb->wc_product_meta_lookup,
			array(
				'rating_count' => absint( $count ),
			),
			array(
				'product_id' => absint( $row['post_id'] ),
			)
		);
	}
}