Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3007373
Show review of variations in product catalog (WPC Show Single Variations 2.1.0)
Closed

Comments

  •  3
    Hugo started the conversation

    Hi there!

    We are using your WPC Show Single Variations 2.1.0 for a long time now and we're very happy with it. However, it looks like review stars are not shown for variation products in product catalog and it only appears for main products. 


    Is there a way to also show the review stars on these variable products?

    Thanks in advance!


    Hugo

  •  1,226
    Dustin replied

    Hi Hugo,

    By default, you can leave a review for the main variable product only. So, you also can show the review rating of the main product for all variations.

    Please add the below custom code (How to add custom code?)

    add_filter( 'woocommerce_product_get_rating_html', 'woocommerce_variation_get_rating_html', 99 );
    function woocommerce_variation_get_rating_html( $rating_html ) {
        global $product;
        if ( $product && $product->is_type( 'variation' ) ) {
            $parent = wc_get_product( $product->get_parent_id() );
            $rating = $parent->get_average_rating();
            $count  = 0;
            if ( 0 < $rating ) {
                $label = sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $rating );
                return '<div class="star-rating" role="img" aria-label="' . esc_attr( $label ) . '">' . wc_get_star_rating_html( $rating, $count ) . '</div>';
            }
        }
        return $rating_html;
    }

    Best regards,
    Dustin