• Resolved Tom

    (@tomwenk)


    Hey, it’s me again. After I can send all schema data cleanly to google with the SEO plugin Rankmaths and the Site Reviews plugin together, there is only one small problem. The stars are not shown in the preview of Rankmaths. To get the stars displayed in the RankMaths preview via the site reviews plugin, I need a code from you.

    RankMaths gave me the following Code:

    
    add_filter( 'woocommerce_product_get_average_rating', function( $rating ) {
    	if ( ! is_admin() ) {
    		return $rating;
    	}
    
    	return 1; // Change this with Site Reviews Plugin function/code to get the ratings value.
    } );

    Now I only need the code from you, which gives me the stars & then everything runs great. Thank you so much!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    1. Is that a Woocommerce hook or a RankMaths hook, and do you have an URL that I can view which provides documentation for it?

    2. What does the $rating variable contain?

    You can use this to find out: glsr_debug($rating);

    3. Do you have access to the product post ID in that hook? Or, does get_the_ID() work in that hook to get the product ID?

    4. Have you tried using the glsr_get_rating helper function? Please see the Help > Functions page for more info.

    • This reply was modified 4 years, 4 months ago by Gemini Labs.
    Thread Starter Tom

    (@tomwenk)

    1. Is that a Woocommerce hook or a RankMaths hook, and do you have an URL that I can view which provides documentation for it?

    I think it’s a RankMaths hook. They gave the code to me to show your Site Reviews – Star-Ratings in the RankMaths Google Preview.

    2. What does the $rating variable contain?

    I think the 5 Stars

    3. Do you have access to the product post ID in that hook? Or, does get_the_ID() work in that hook to get the product ID?

    I have asked RankMaths support

    ___________________________

    I think that should be the code I have to include. How does the code link with the RankMaths code?

    $ratingInfo = glsr_get_rating([
        'assigned_to' => 'post_id',
    ]);
    
    // OR:
    
    $ratingInfo = apply_filters('glsr_get_rating', null, [
        'assigned_to' => 'post_id',
    ]);
    Plugin Author Gemini Labs

    (@geminilabs)

    I imagine, based on the provided information, that you would do something like this:

    add_filter('woocommerce_product_get_average_rating', function ($rating) {
        $args = ['assigned_to' => 'post_id'];
        if (is_admin() && $ratingInfo = apply_filters('glsr_get_rating', null, $args)) {
            return $ratingInfo->average;
        }
        return $rating;
    });
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘RankMaths Preview with SiteReview Stars’ is closed to new replies.