Product schema issue

#78959
  • Resolved Leo
    Rank Math free

    In order to fully comply with google product schema, i have this snippet in my functions.php:

    add_filter( 'woocommerce_structured_data_product', 'bomberomania_microdata', 10, 2 );
    
    function bomberomania_microdata( $markup, $product ){
    	
    // 
    // We collect reviews instore and from a 3rd party. Sometimes 3rd party send incompatible value, so we fix here
    //
    //
    
        if ( isset($markup['aggregateRating']) ) {
        
            if ( $markup['aggregateRating']['ratingValue'] > 5 || $markup['aggregateRating']['ratingValue'] <= 1 ){
    		
                $markup['aggregateRating']['ratingValue'] = 5;
            }
    	}
    	
    
    // Woocommerce attribute pa_marca as "brand" is already set in rankmath setup. 
    // But in some products pa_marca is empty, so we fix here
    	
    	$brand = $product->get_attribute('pa_marca');
    
    	$brands = explode( ',', $brand );
    	if ( ! empty( $brands ) ) {
    		$marca = $brands[0];
    	}else{
    		$marca = 'BOMBEROMANÍA';
    	}
    	
    	$markup['brand'] = array(
    	
    	'@type'	=> 'Brand',
    	'name'	=> $marca,
    	
    	);
    	
    // We use product Gtin codebar as our sku. No need to add another field, just fill from there
    	
    	$markup['gtin13'] = $product->get_sku();
    
    	return $markup;
    }
    

    Issue is, now that we use rankmath, i’m not getting this values in frontstore

    How can i translate this snippet to rankmath’s code?

    We have 2000+ products in our store and this simplify management, so everything must be done in this bulk way

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Rank Math takes the schema data from your product pages automatically and turns it into Schema-ready content. Likewise, the aggregateRating and review fields are taken from your actual product reviews that your buyers/customers leave on your products.

    You can fix the SKU and availability issue easily as well:

    To fix the brand issue, head over to WordPress Dashboard > Rank Math > General Settings > WooCommerce and choose from any of the available fields to use as your product’s brands.

    Brand Value

    If you want to use a custom value for your Brands, you can do that by using the following code in your theme’s functions.php file:

    // Add Brand for Products.
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    $entity['brand'] = 'Rank Math;
    return $entity;
    });

    Replace the “Rank Math” text with your actual brand name then run your website through the Structured Data Testing tool once again.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hello,

    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 1 replies (of 1 total)

The ticket ‘Product schema issue’ is closed to new replies.