Google Merchant Feed – Automatic item updates

#349696
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    The method we use for the Schema markup is according to Google guidelines for the Product Schema: https://developers.google.com/search/docs/advanced/structured-data/product

    However, if you would like to modify that to show each offer and its data individually you can add and modify this filter to your particular needs:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        if ( ! is_product() ) {
            return $entity;
        }
    
        $product = wc_get_product( get_the_ID() );
        if ( ! $product->is_type( 'variable' ) ) {
            return $entity;
        }
    
        $variations = $product->get_available_variations();
        if ( ! empty( $variations ) ) {
            $offers = [];
            foreach ( $variations as $variation ) {
                $price_valid_until = get_post_meta( $variation['variation_id'], '_sale_price_dates_to', true );
                $offers[] = [
                    '@type'           => 'Offer',
                    'description'     => strip_tags( $variation['variation_description'] ),
                    'price'           => $variation['display_price'],
                    'priceCurrency'   => get_woocommerce_currency(),
                    'availability'    => $variation['is_in_stock'] ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock',
                    'itemCondition'   => 'NewCondition',
                    'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : '2025-12-31',
                    'url'             => $product->get_permalink(),
                    'sku'             => $variation['sku'],
                ];
            }
        }
    
        $entity['offers'] = $offers;
    
        return $entity;
    } );

    You can change each property according to your needs and remove any properties that you don’t require for the offers.

    The filter should be added to your active theme’s functions.php file. Here’s another way to apply the filter using the rankmath.php file:
    https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php

    Lastly, we also recommend that you read through this guide to learn more about the way Google tries to identify the price and the guidelines that you need to set for your prices on the website: https://support.google.com/merchants/answer/6324371

    I hope that helps.

    Thank you.

    Engine Room
    Rank Math business

    Amazing, thank you so much.

    I modified it slightly to suit my purpose and this is below in case anyone finds it helpful:

    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        if ( ! is_product() ) {
            return $entity;
        }
    
        $product = wc_get_product( get_the_ID() );
        if ( ! $product->is_type( 'variable' ) ) {
            return $entity;
        }
    
        $variations = $product->get_available_variations('objects');
        if ( ! empty( $variations ) ) {
            $offers = [];
            foreach ( $variations as $variation ) {
                $price_valid_until = $variation->get_date_on_sale_to();
    
                $offers[] = [
                    '@type'           => 'Offer',
                    'description'     => $variation->get_name(),
                    'price'           => $variation->get_price(),
                    'priceCurrency'   => get_woocommerce_currency(),
                    'availability'    => $variation->get_stock_status() ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock',
                    'itemCondition'   => 'NewCondition',
                    'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : date('Y-m-d', strtotime('+2 years')),
                    'url'             => $product->get_permalink(),
                    'sku'             => $variation->get_sku(),
                ];
            }
        }
    
        $entity['offers'] = $offers;
    
        return $entity;
    } );
    

    Hello,

    Glad that helped, and thank you for sharing the working filter on your site.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

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

The ticket ‘Google Merchant Feed – Automatic item updates’ is closed to new replies.