Only GTIN or MPN into WooCommerce Richsnippets left

#29834
  • Resolved Holger Gaier
    Rank Math free

    With help from other peoples previous support tickets I was able to get from 6 mistakes or problems with the Google messages to only one.

    here is the code I use with function.php

    
    /**
     * Filter to modify schema data.
     * @brand for products
     * @param array $entity Snippet Data :        
     * @return array
     */
    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    	$entity['brand'] = 'yourbrandhere';
    	$entity['offers']['priceValidUntil'] = '2020-12-31';
    	$entity['gtin13'] = str_replace('-', '',$entity['gtin']);
    	return $entity;
    });
    
    

    Only the one with the gtin13 is not working. And MPN I need also for some products. My woocommerce 3.9.1 has both entities already build in(?).

    See here: https://i.ibb.co/Bs06D6C/Screenshot-31-01-20-21-55.jpg

    What code would bring both GTIN and MPN into the Schema? Thanks for your help.

    • This topic was modified 4 years, 10 months ago by Holger Gaier.
    • This topic was modified 4 years, 10 months ago by Holger Gaier. Reason: solved
    • This topic was modified 4 years, 10 months ago by Holger Gaier. Reason: Thank you
Viewing 4 replies - 16 through 19 (of 19 total)
  • Hello,

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

    Thank you.

    Hello,

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

    Thank you.

    So thank you Todd and Michael for all your effort and input. Even though you did not lead me directly to the solution, you helped me get there and I learned a lot. The support from Vendidero gave me the right code, that works fine.

    In case you have other like me pestering you about Germanization GTIN/MPN, here is the code that is working with me:

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
        global $product;
    
        if ( is_a( $product, 'WC_Product' ) ) {
            $entity['gtin13'] = WC_trusted_shops()->trusted_shops->get_product_gtin( $product );
        }
    
        return $entity;
    });

    Thanks and have a great day. 🙂

    Hi Holger,

    Thank you for the reply.

    I am glad that you finally got this to work 🙂

    Feel free to contact us for any additional questions, we are always happy to help!

Viewing 4 replies - 16 through 19 (of 19 total)

The ticket ‘Only GTIN or MPN into WooCommerce Richsnippets left’ is closed to new replies.