The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Prevent other custo...
 
Share:
Notifications
Clear all

Limited Support

Our support team is currently on holiday from December 25, 2025 to January 7, 2026, and replies may be delayed during this period.

We appreciate your patience and understanding while our team is away. Thank you for being part of the wpDiscuz community!

Merry Christmas and Happy Holidays! πŸŽ„

[Solved] Prevent other custom rating fields from reducing the product rating

8 Posts
2 Users
0 Reactions
9,718 Views
Posts: 9
Topic starter
(@zo-zo-lee)
Active Member
Joined: 5 months ago

I found a solution that seems to work with custom code to force woocommerce to look only at my custom rating_product key

/**
 * Force WooCommerce to use only the main 'rating' meta and ignore 'size_fit'
 */
add_filter('woocommerce_product_get_average_rating', 'custom_woocommerce_average_rating', 20, 2);

function custom_woocommerce_average_rating($average, $product) {
    // Get all comments/ratings for the product
    $args = array(
        'post_id' => $product->get_id(),
        'status' => 'approve',
        'meta_key' => 'rating_product', // Only get comments with your custom rating field
    );
    
    $comments = get_comments($args);
    
    if (!$comments) return $average;
    
    $total = 0;
    $count = 0;
    
    foreach ($comments as $comment) {
        $rating = get_comment_meta($comment->comment_ID, 'rating_product', true);
        if ($rating) {
            $total += (float) $rating;
            $count++;
        }
    }
    
    return ($count > 0) ? ($total / $count) : $average;
}

Reply
Page 2 / 2
Share: