wc_update_product_lookup_tables_rating_count() WC 3.6.0
Populate rating count lookup table data for products.
No Hooks.
Return
Null. Nothing.
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. |
Code of wc_update_product_lookup_tables_rating_count() wc update product lookup tables rating count WC 5.0.0
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'] ),
)
);
}
}