richSnippet Product Price

  • One of our clients is having an issue with their Google Ad account where the products being sent across on the feed are being rejected. We’ve manage to track this down to an issue with the richSnippet code that’s being added by Rank Math.

    This is happening when products have variations, say a product has 3 variations each is sent across to Google as an individual product line. The price passed across to the feed is the price of that specific variation. To load the variation by default you are able to pass parameters across on the URL, these are sent to Google and on page load the variation it selected and the relevant price shown. However, with Rank Math the richSnippet always shows the price as the lower variation available on that product.

    Is there any scope to allow the price that’s shown to be the price of the variation that’s been selected via the URL parameters?

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

    Thank you for contacting Rank Math today.

    I am not so sure if using URL Parameters will hep your issue. You can however add the following code to your theme functions.php file provide the schema entities for each of the variations. You can use it as it is or change to only assign price for your variations:

    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' ) ) {
    		$entity['gtin13'] = get_post_meta( get_the_ID(), 'hwp_var_gtin', true );
    		return $entity;
    	$variations = $product->get_available_variations();
    	if ( ! empty( $variations ) ) {
    		$entity['offers'] = [];
    		foreach ( $variations as $variation ) {
    			$price_valid_until = get_post_meta( $variation['variation_id'], '_sale_price_dates_to', true );
    			$entity['offers'][] = [
    				'@type'           => 'Offer',
    				'description'     => strip_tags( $variation['variation_description'] ),
    				'price'           => $variation['display_price'],
    				'priceCurrency'   => get_woocommerce_currency(),
    				'availability'    => $variation['is_in_stock'] ? '' : '',
    				'itemCondition'   => 'NewCondition',
    				'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : '2025-12-31',
    				'url'             => $product->get_permalink(),
    				'gtin13'          => get_post_meta($variation['variation_id'],'hwp_var_gtin', true ),
    	return $entity;
    } );

    Hope this helps you. Please let us know if you have any further questions.

    Perfect, thanks for this I’ll git it a go


    We are glad we could help.

    Let us know if you need further assistance.

    Thank you


    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘richSnippet Product Price’ is closed to new replies.