Product in search console

#66090
  • Resolved Thibaut Fontaine
    Rank Math pro

    Hello,

    All my products are not declared to the search console.How can I declare them to the search console?

    Also, there are missing fields: https://ibb.co/gMvL1by

    It can be that we generate a URL for each variation as you can see here:
    https://lerepaireduchef.fr/bar Barbecue-kamado/

    However it would be possible to add the missing info by adding the info of the default variation on the URL declared with the search console.

    Here is how the information for our google shopping feed is mapped, maybe it will help you answer me: https://ibb.co/6tbVwc

    thanks in advance

Viewing 15 replies - 16 through 30 (of 33 total)
  • Hello,

    The code is working fine but it doesn’t seem to be getting the gtin value from your products. Please keep the logins open while I consult the dev team on this.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    That’s why, we have to use the information of the default variation to schema.org.

    What exactly do you mean by this? Variations and attributes are both part of the same product. You can simply add gtin attribute in Product attributes which Rank Math will show in the schema data.

    I am not sure what data you want to use in the gtin. The gtin variables are missing in both the links you provided in your previous reply.

    If you want to dynamically change the gtin values in all your products without adding the attribute in the backed then please use following filter code:

    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        $entity['gtin13'] = 'Gtin value'; // You can use here get_post_meta() function to add the value from cutom field in gtin attribute.
        return $entity;
    });
    

    I hope that helps. Please let us know if you need any further assistance.

    Thank you.

    hello Pratik,

    When I said ”That’s why, we have to use the information of the default variation to schema.org.”

    I take an example with one product : https://lerepaireduchef.fr/crepiere-professionnelle/

    In search console, my general URL is https://lerepaireduchef.fr/crepiere-professionnelle/ .
    Except that as you can see, I only use variable products. A URL is created for each variation :
    https://lerepaireduchef.fr/crepiere-professionnelle/?attribute_pa_chassis=rond&attribute_pa_crepe=35-cm&attribute_pa_epaisseur=fonte
    https://lerepaireduchef.fr/crepiere-professionnelle/?attribute_pa_chassis=carre&attribute_pa_crepe=35-cm&attribute_pa_epaisseur=fonte
    Etc.

    In order to add a GTIN for each variation I use this plug in : WooCommerce UPC, EAN, and ISBN. The meta function seems to be hwp_var_gtin or hwp_product_gtin. You can check my back office in product page (données produit > Variations > Gtin)

    There are two errors related to this:

    1. The gtin does not appear in my structured data.

    2. I cannot fill in the GTIN field in the inventory since it is already in the variations. WordPress tell me a duplicate GTIN error. That’s why I would like use GTIN of variation by default.

    I can test with this two codes, can you tell me what modifications i need to make? :
    /**
    * Filter to add GTIN to Variable Products.
    *
    * @param array $entity Snippet Data
    * @return array
    */
    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    $product = new WC_Product( get_the_ID() );
    if( $product->is_type( ‘simple’ ) ){
    $gtin_value = get_post_meta($product->get_id(),’_wpm_gtin_code’, true);
    $entity[‘gtin13’] = $gtin_value;
    return $entity;
    }elseif($product->is_type( ‘variable’ )){
    $variation = new WC_Product_Variation(get_the_ID());
    $gtin_value = get_post_meta($variation->get_id(),’_wpm_gtin_code’, true);
    $entity[‘gtin13’] = $gtin_value;
    return $entity;
    }else{
    return $entity;
    }

    });

    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    $entity[‘gtin13’] = ‘Gtin value’; // You can use here get_post_meta() function to add the value from cutom field in gtin attribute.
    return $entity;
    });

    Thanks in advance

    Hello,

    Rank Math doesn’t add a new Offer entity in the schema data for each variation. So a Product will have only 1 Gtin value in the schema data. To use the default attribute value in gtin, please use the filter I gave you before with the get_post_meta() function to get the GTIN value from the postmeta table if that’s where the plugin stores the gtin value.

    Here is an example:

    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        $entity['gtin13'] = get_post_meta( 'Product/VariationID', 'gtin_meta_key', true );
        return $entity;
    });
    

    I hope that helps.

    Hello Pratik,

    I have tried several codes and none of them work, I must have been wrong.

    You have access to my website, can you give me the correct code to add please?

    Thank you

    Hello,

    Sorry, but we don’t know where exactly the WooCommerce UPC, EAN, and ISBN plugin stores the GTIN value in the Database. I suggest you contact the WooCommerce UPC team and ask them to provide the code to get the GTIN value by product/variation ID. Once they provide the function you can use it in the filter I gave you before.

    I hope that helps.

    Hi pratik,

    It’s seems to be : get_post_meta ($ variation [‘variation_id’], ‘hwp_var_gtin’, 1);

    What is the right code please ?

    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    $entity[‘gtin13’] = ‘($ variation [‘variation_id’], ‘hwp_var_gtin’, 1);
    return $entity;
    });

    This is the right post meta :

    get_post_meta( $variation[‘variation_id’], ‘hwp_var_gtin’, 1 );

    I tested with this two codes and in the test of schema.org I have GTIN13 ”False” but the GTIN are true :

    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    $entity[‘gtin13’] = get_post_meta( $variation[‘variation_id’], ‘hwp_var_gtin’, 1 );
    return $entity;
    });

    get_post_meta( $post_id, ‘hwp_product_gtin’, 1 );

    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    $entity[‘gtin13’] = get_post_meta( $post_id, ‘hwp_product_gtin’, 1 );
    return $entity;
    });

    Hello,

    Can you please tell us what code are you using to get the variation ID?

    
    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    $entity[‘gtin13’] = get_post_meta( $variation[‘variation_id’], ‘hwp_var_gtin’, 1 );
    return $entity;
    });
    
    get_post_meta( $post_id, ‘hwp_product_gtin’, 1 );
    
    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    $entity[‘gtin13’] = get_post_meta( $post_id, ‘hwp_product_gtin’, 1 );
    return $entity;
    });
    

    This code looks incomplete to me. Here the $variation[‘variation_id’] & $post_id both will return null and the get_post_meta function will not return any value.

    First, you’ll have to get the variations object by product ID, and then from that object you’ll have to find the default variation. I am not sure what default variation you want to use but if you want to show the gtin value from the first variation then you can use something like $variation[0]['variation_id']

    
    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['gtin13'] = get_post_meta( $variations[0]['variation_id'], 'hwp_var_gtin', true );
        }
    
        return $entity;
    } );
    

    Please try adding this code to your theme’s functions.php file. This again is example code and it will work only if the plugin stores the value in the hwp_var_tin meta in postmeta table.

    If this doesn’t fix the issue, then please check if the gtin value exists in the hwp_var_gtin meta in postmeta table for the specific variation ID.

    I hope that helps.

    Hello Pratik,

    we are going forward 🙂 It’s good for GTINs. Thank you so much !

    My last mistake is related to the price.

    I have correctly configured the price with VAT on woocommerce but in the structured data it is still the price excluding VAT that is displayed.

    This is very important because it generates errors in google shopping.
    I inquired and I was told about this function: woocommerce_structured_data_product_offer

    Thank you for helping me !

    In order to follow the issue :

    1. Yes, I will enter the rates including VAT. Unfortunately this changes all the prices on my shop! With this option I will have to go and modify all my prices one by one.

    2. I was told about this otpion too:
    Now Rank works with arrays for json-ld data, so if the operation does not suit you, you have to hook your products, in it you modify the price, at worst you disable the snippets for your products and you add a hook that sends all the json-ld data. To have the structure of the table you do a var_dump when the option is activated, you will have the detail of the table.

    Hello,

    I replied to your other ticket: https://support.rankmath.com/ticket/product-in-search-console/page/2/?view=all

    Please let us know if the Gtin issue is fixed so we can close this ticket.

    Thank you.

    Yes the GTIN are good ! thanks 😉

    Hello,

    I have an error critic in this page, it’s come frome rankmath ? :https://lerepaireduchef.fr/garantie/

    AH01071: Got error ‘PHP message: PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘rewrite_search_slug_pagination’ not found or invalid function name in /var/www/vhosts/lerepaireduchef.fr/httpdocs/wp-includes/class-wp-hook.php on line 287PHP message: PHP Fatal error: Uncaught Error: Call to a member function get_price() on null in /var/www/vhosts/lerepaireduchef.fr/httpdocs/wp-content/plugins/woocommerce/includes/wc-product-functions.php:962\nStack trace:\n#0 /var/www/vhosts/lerepaireduchef.fr/httpdocs/wp-content/themes/themify-ultra-child/functions.php(327): wc_get_price_including_tax()\n#1 /var/www/vhosts/lerepaireduchef.fr/httpdocs/wp-includes/class-wp-hook.php(287): {closure}()\n#2 /var/www/vhosts/lerepaireduchef.fr/httpdocs/wp-includes/plugin.php(249): WP_Hook->apply_filters()\n#3 /var/www/vhosts/lerepaireduchef.fr/httpdocs/wp-content/plugins/seo-by-rank-math/includes/traits/class-hooker.php(103): apply_filters_ref_array()\n#4 /var/www/vhosts/lerepaireduchef.fr/httpdocs/wp-content/plugins/seo-by-rank-math/includes/opengraph/class-opengraph.php(173): RankMath\\OpenGraph\\OpenGraph->do_filter()\n#5 /var/www/vhosts/lerepaireduchef.fr/httpdocs/wp-content/plugins/seo-by-rank-math/includes/opengraph/class-facebook.php(338): RankMath\\OpenGr…’

    And in my function.php I added this code yesterday for GTIN :

    // GTIN données structurées

    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[‘gtin13’] = get_post_meta( $variations[0][‘variation_id’], ‘hwp_var_gtin’, true );
    }

    return $entity;
    } );

Viewing 15 replies - 16 through 30 (of 33 total)

The ticket ‘Product in search console’ is closed to new replies.