No global identifier provided (e.g., gtin, mpn, isbn)

  • Hi,
    i have this problem and i installed plugin (Product GTIN (EAN, UPC, ISBN) for WooCommerce) to fix it
    it fixed some products and removed the warning but it didn’t work with the majority of the products with the added GTIN codes
    what should i do? it there a plugin that is more compatible with rank math??
    thank you,

    • This topic was modified 1 month, 1 week ago by Ahmed Sa'eed. Reason: adding login link
Viewing 9 replies - 16 through 24 (of 24 total)
  • Hi, yes i already have it installed and using it with some products but the problem is with them as i mentioned before

    Hi,
    i have this problem and i installed plugin (Product GTIN (EAN, UPC, ISBN) for WooCommerce) to fix it
    it fixed some products and removed the warning but it didn’t work with the majority of the products with the added GTIN codes
    what should i do? it there a plugin that is more compatible with rank math??
    thank you,

    Hello,

    Thank you fro contacting Rank math today.

    I have added the following code to your function.php and it seems to have fixed the issue with global identifier o our shared URL, please check attached screenshot.

    /**
     * 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['gtin8'] = $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['gtin8'] = $gtin_value;
             return $entity;
        }else{
             return $entity;
        }
        
    });

    To fix the brand warning, 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.

    It works now thank you very much 🙂

    Hello Ahmed,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    This works, thanks

    /**
    * 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[‘gtin8’] = $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[‘gtin8’] = $gtin_value;
    return $entity;
    }else{
    return $entity;
    }

    });

    Works for produtcs but broke my home

    2020-06-29T17:28:24+00:00 CRITICAL Uncaught Exception: Produto inválido. in /home/409312.cloudwaysapps.com/mzgvydvmzd/public_html/wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php:165
    Stack trace:
    #0 /home/409312.cloudwaysapps.com/mzgvydvmzd/public_html/wp-content/plugins/woocommerce/includes/class-wc-data-store.php(159): WC_Product_Data_Store_CPT->read(Object(WC_Product))
    #1 /home/409312.cloudwaysapps.com/mzgvydvmzd/public_html/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(135): WC_Data_Store->read(Object(WC_Product))
    #2 /home/409312.cloudwaysapps.com/mzgvydvmzd/public_html/wp-content/themes/flatsome-child/functions.php(52): WC_Product->__construct(59)
    #3 /home/409312.cloudwaysapps.com/mzgvydvmzd/public_html/wp-includes/class-wp-hook.php(287): {closure}(Array)
    #4 /home/409312.cloudwaysapps.com/mzgvydvmzd/public_html/wp-includes/plugin.php(249): WP_Hook->apply_filters(Array, Array)
    #5 /home/409312.cloudwaysapps.com/mzgvydvmzd/public_html/wp-content/plugins/seo-by-rank-math/incl, em /home/409312.cloudwaysapps.com/mzgvydvmzd/public_html/wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php, na linha 165

    Hello,

    Try to change the code to this one, so the code only runs on product pages:

    /**
    * 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 ) {
       if(is_product()){
         $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[‘gtin8’] = $gtin_value;
         }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[‘gtin8’] = $gtin_value;
         }
       }
       
       return $entity;
    });

    Looking forward to help you.

    For me, works perfectly with this on functions.php for single product

    /**
    * Adding Custom GTIN Meta Field
    * Save meta data to DB
    */
    // add GTIN input field
    add_action(‘woocommerce_product_options_inventory_product_data’,’woocom_simple_product_gtin_field’, 10, 1 );
    function woocom_simple_product_gtin_field(){
    echo ‘<div id=”gtin_attr” class=”options_group”>’;
    //add GTIN field for simple product
    woocommerce_wp_text_input(
    array(
    ‘id’ => ‘_gtin’,
    ‘label’ => ‘GTIN’,
    ‘desc_tip’ => ‘true’,
    ‘description’ => ‘Enter the Global Trade Item Number (UPC,EAN,ISBN)’)
    );
    echo ‘</div>’;
    }
    // save simple product GTIN
    add_action(‘woocommerce_process_product_meta’,’woocom_simple_product_gtin_save’);
    function woocom_simple_product_gtin_save($post_id){
    if(isset($_POST[‘_gtin’]) && !empty($_POST[‘_gtin’])) {
    $gtin = sanitize_text_field($_POST[‘_gtin’]);
    update_post_meta($post_id,’_gtin’, $gtin);
    }
    }

    /**
    * Filter to add customize product schema.
    *
    * @param array $entity Snippet Data
    * @return array
    */
    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    global $post;
    $gtin_value = get_post_meta($post->ID,’_gtin’, true);
    if($gtin_value){
    $entity[‘gtin8’] = $gtin_value;
    return $entity;
    }
    return $entity;
    });

    /**`

    Hello Jhoni,

    Thank you for the info.

    Let us know if you need our help with anything else.

    Looking forward to helping you. Thank you.

    ​​​​​​

Viewing 9 replies - 16 through 24 (of 24 total)

You must be logged in to reply to this ticket.