Only GTIN or MPN into WooCommerce Richsnippets left

  • 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 1 month, 3 weeks ago by Holger Gaier.
    • This topic was modified 1 month, 3 weeks ago by Holger Gaier. Reason: solved
    • This topic was modified 1 month, 3 weeks ago by Holger Gaier. Reason: Thank you
Viewing 15 replies - 1 through 15 (of 19 total)
  • Hi Holger,

    The code you are using should add your GTIN as your GTIN13 data.

    Can you please share the URL where you are seeing this issue so that we can help?

    Thank you.

    Hello,

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

    Thank you.

    Hello Todd,

    thanks for taking your time to look at the problem. Any idea, what could be the problem?

    HI Holger,

    Thanks for getting back to us.

    I can suggest that you identify the plugin that is adding the extra fields on the page which will then make it easier to get the MPN or GTIN value from the current product using the plugin’s native API functions.

    I hope this info helps. Thank you.

    Ah, it is not Woocommerce itself… ok, great.
    Thanks for this tip.

    It is the germanized plug-in.
    And I got this from their help:

    add_action( 'woocommerce_product_additional_information', 'my_child_add_ean', 10 );
    
    function my_child_add_ean( $product ) {
        echo '<p>GTIN: ' . WC_germanized()->trusted_shops->get_product_gtin( $product ) . '</p>';
        echo '<p>MPN: ' . WC_germanized()->trusted_shops->get_product_mpn( $product ) . '</p>';
    }

    Can I just put that under the former in the function.php under or above what I got from you?

    Hello,

    You can put it below the code we provided.

    Let us know if you need further assistance from us.

    Thank you.

    Hello Todd,

    thanks for reaching out again.

    I am sorry, but this code from germanized is not helping anything. That was made to print the GTIN on a individual product page.

    Here is their answer from venidero, the maker of germanization, I gave them your code and they had this question with it:

    The question is, what exactly is $entity? The problem is that the actual product object or ID is not passed on, so that the product cannot be accessed from there to output additional data. Can you please inquire at RankMath Support about how to get the proper product within the filter so that data can be read out? Unfortunately, this cannot work.

    Hi Holger,

    Thank you for the reply.

    $entity is an array containing the snippet data for the schema that you are trying to modify.
    Could you please try to get the value from the global $product object like so:

    /**
     * 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 ) {
            global $product;
    	$entity['brand'] = 'yourbrandhere';
    	$entity['offers']['priceValidUntil'] = '2020-12-31';
    	$entity['gtin'] = WC_germanized()->trusted_shops->get_product_gtin( $product );
    	return $entity;
    });
    

    Let me know how this goes. Thank you.

    Hello Michael,

    It broke my product pages, not available. So not too good.
    With the two // is all good again. 🙂 Thanks for the idea.
    Maybe you can get me the right code for the second php snippet?

    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    	global $product;
    $entity['brand'] = 'com';
    	$entity['offers']['priceValidUntil'] = '2020-12-31';
    	$entity['gtin'] = WC_germanized()->trusted_shops->get_product_gtin( $product );
    	return $entity;
    });

    Like this also not working.

    • This reply was modified 1 month, 3 weeks ago by Holger Gaier.
    • This reply was modified 1 month, 3 weeks ago by Holger Gaier.
    • This reply was modified 1 month, 3 weeks ago by Holger Gaier. Reason: wrong code, changed it, also not working

    Hello,

    Thanks for getting back to us.

    We might need to take a closer look at the settings and run some tests on the integration with Germanized WC. Please edit the first post on this ticket and include your WP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Right now I have the stupid Germanized/Trusted-Shop Plugin. Additional I put on the code snippet I showed you up there. This is working fine.

    Can you try to see from this what is needed to get me the right code to put GTIN and MPN into RankMathe product Schema array? As I will have no problem using the code snippet instead of Germanized/TrustedShop for GTIN and MPN on all my products.

    Btw. I tried the plugin you recommend before, but that was also not working.

    • This reply was modified 1 month, 3 weeks ago by Holger Gaier. Reason: spelling

    Hello,

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

    Thank you.

    wrong way. deleted.

    • This reply was modified 1 month, 3 weeks ago by Todd.
    • This reply was modified 1 month, 3 weeks ago by Holger Gaier. Reason: anonym
    • This reply was modified 1 month, 3 weeks ago by Holger Gaier.

    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.

Viewing 15 replies - 1 through 15 (of 19 total)

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