Adding meta fields/product attributes to schema data

#150105
  • Resolved Dre
    Rank Math free

    Hi,

    I noticed there are two type of schema for products: “Product” and “Woocommerce product”.

    –>what i the difference?

    –>if I have extra meta fields for products like GTIN/EAN and also other product attributes, how can these be added to Rank Math’s schema? For Google shopping ads there are other things required that Rank Math doe not add by default, such as brand, EAN etc!

    Thank you.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    When you use the product schema, you will need to fill in all the details by hand from SKU, brand, price, and other details including the global identifier.

    If you are using WooCommerce Plugin, I’d recommend using the WooCommerce product schema in which details added in your products are automatically converted to schema ready content by Rank math for your product pages, which makes it easier and efficient for any WooCommerce user.

    The stand-alone product schema is also normally recommended for single posts where your posts are product-related and not for WooCommerce product pages.

    You can also check these links for more information:
    https://rankmath.com/kb/product-schema/
    https://rankmath.com/kb/woocommerce-product-schema/

    I hope that helps. Thank you, and please don’t hesitate to contact us if you need further assistance.

    Dre
    Rank Math free

    Thank you, could you pleae also answer my second question?
    I noticed even when the “Woocommece poduct” schema is enabled, a lot of mark up that is required for Google shopping ads (https://support.google.com/merchants/answer/7052112?hl=en), for example brand, GTIN etc, is NOT displayed in Rank Math schema!

    So how can I add it and if I have custom fields, how can I add these to the schema?

    Oh, and I noticed Rank Math is unfotunately using the price without tax (because we are entering pices without tax in backend), but prices are diplayed including tax in fontend and should also be including tax in schema!

    Hello,

    To add the brand from custom fields you would need to modify the schema using the following filter:

    
    /**
     * Filter to add Brand Name for Products.
     *
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        $entity['brand'] = 'Rank Math';
        $entity['GTIN'] = 'RM_GTIN';
        return $entity;
    });

    To have your products included in schema tax inclusive, use the following filter:

    
    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
        global $product;
        $entity['offers']['price'] = wc_get_price_including_tax( $product );
        return $entity;
    });
    

    These functions can be added as one. You will be adding the filters to your theme functions.php file.

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

    Dre
    Rank Math free

    Hi,
    thank you. So now I have added

    add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
        global $product;
        $entity['offers']['price'] = wc_get_price_including_tax( $product );
        $entity['gtin8'] = get_post_meta(get_the_ID(), 'gtin', TRUE);
        return $entity;
    });

    and I have a few additional questions:

    1. The code above is adding the GTIN to the schema, but not to the Open Graph links (meta link og). Why not?

    2. Also, I don’t have reviews enabled in Woocommerce settings, what should I do in this case about the “review” and “aggregateRating” warnings?

    3. Regarding the price: I noticed Rank Math has two price mark ups, one in “offers” and one in “price specification”. And the code you provided me is only including the tax to the offers section, why not to the other section? And in the Open Graph meta links the price is still without tax as well.

    Thank you!

    Hello,

    Thank you for the follow up.

    1&3. To add or modify any value related to opengrapgh, you would use this filter: https://rankmath.com/kb/filters-hooks-api-developer/#1-filter-to-change-opengraph-type-ogtype

    2. If you don’t have any reviews yet, that is going to show up as a warning in the schema testing tool. That’s because Google will actually look for those fields. These should however not worry you as they are not errors.

    3. In the code I shared, I have specified to change the offers price: $entity['offers']['price']. This is usually the price shown by Google in SERPs. If you wish to change any other entity in your schema, you would need to follow a similar pattern

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

    This looks very technical to me.

    I need an easier way to add product attributes to the schema.

    As Google Shopping and all its related fields is getting more and more important, where do I place this as a feature request.

    A feature where you can select attributes of products and map them.
    Something like the GTIN field you provide just extended for any field Google mentions.

    Hello Edward,

    Given you have the Pro version, you can use the advanced schema editor to add your custom properties and values to your product schema:
    img

    Just ensure the follow Google guidelines on product schema:https://developers.google.com/search/docs/data-types/product

    Hope this helps.

    Of course, it does, Michael,

    Now I have to figure out how to call these attributes in that editor.

    Is it as simple as writing %attribute_name% in the value field?

    Hello,

    For wooCommerce attributes, you can use the %customterm()% variable, for example %customterm(pa_attribute)% as shown here: https://i.rankmath.com/a1lb45. This will get the specified attribute and get the and fill it as your value. Let us know if this works for you

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

    I will give it a go using the brand attribute because I have that stored as a product attribute.
    Thanks, Michael.

    Hello,

    @Edward We are glad it worked for you.

    If you have any other concerns, please don’t hesitate to contact us anytime by creating a new ticket to assist you further with anything else.

    Thank you.

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

The ticket ‘Adding meta fields/product attributes to schema data’ is closed to new replies.