AggregateOffers

#30887
  • Resolved Annie
    Rank Math free

    Hi,
    Thanks for creating and supporting a great plugin, it’s quite impressive.

    I run a comparison site with offers in content egg so I’m trying to have my offers displayed as a type of AggregateOffer – see screenshot attached. So there might be 4 offers for the same product at different companies and I want google to display the range of prices.

    aggregateoffer

    I need to display the type, highprice, lowprice, count, and based on your excellent support KB I’ve gotten this far:

    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {

    $entity[‘gtin13’] = str_replace(‘-‘, ”,$entity[‘sku’]);
    $entity[‘offers’][‘@type’] = ‘AggregateOffer’;
    $entity[‘offers’][‘lowPrice’] = $entity[‘offers’][‘price’];
    $entity[‘offers’][‘highPrice’] = $high_price ;
    $entity[‘offers’][‘offerCount’] = $count;
    unset($entity[‘offers’][‘price’]);
    unset($entity[‘offers’][‘availability’]);

    … can you let me know :
    a) is this the right way to go about this or is there a better way for RankMath to recognise Aggregate Offers?
    b) If there’s no alternative, I’ve got some code which works out what the highest price and count of offers, but I need to pass in the product_id – how can I get the product id? I’ve tried setting global $product and using $product->get_id() but it doesn’t seem to like it in the functions.php

    Thank you very much in advance, I hope this isn’t out of scope of your support.

    • This topic was modified 4 years, 8 months ago by Annie.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Annie
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    a). Yes this would work but you can also extend the JSON-LD data from Rank Math by using the following filter:

    /**
     * Collect data to output in JSON-LD.
     *
     * @param array  $unsigned An array of data to output in json-ld.
     * @param JsonLD $unsigned JsonLD instance.
     */
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	return [];
    }, 10, 2);

    b). Both global $product and using $product->get_id() should be able to get the value of the current product in the loop. Could you please debug your code line by line to check if some of the functions are not returning the expected data?

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Annie
    Rank Math free

    Thanks so much for the input. I’m not sure why $product->get_id() didn’t work earlier but it seems fine now.

    I’m happy to revise to use rank_math/json_ld if there is a performance or some other benefit – can you let me know if there’s likely be any improvement?

    Thanks again for the speedy help !
    Cheers,

    Todd
    Rank Math free

    Hi Annie,

    I am so glad to hear that it is working now.

    It is working with the code is the biggest advantage I would imagine 🙂

    If you need help with anything else, please open a new support ticket here so we can help:

    https://support.rankmath.com

    We are always here for assistance.

Viewing 4 replies - 1 through 4 (of 4 total)

The ticket ‘AggregateOffers’ is closed to new replies.