Re: How to Add Shopify Variant Metafields to JSON-LD for Rich Results Without Breaking Structured Da

How to Add Shopify Variant Metafields to JSON-LD for Rich Results Without Breaking Structured Data?

cmcorganic
Visitor
1 0 0

 

I'm trying to add variant-specific metafields to my Shopify product JSON-LD structured data to ensure that each variant gets properly indexed and displayed in Google's rich results.

I have the following metafields at the variant level:

  • custom.strain
  • custom.strain_type
  • custom.category
  • custom.strain_genetics
  • custom.strain_description
  • custom.thc_percentage
  • custom.strain_effects
  • custom.3rd_party_test_results

I'm currently including these metafields in the offers section of the JSON-LD for each variant like code attached

 

"offers": [
  {%- for variant in product.variants -%}
    {
      "@type": "Offer",
      "price": "{{ variant.price | money_without_currency | replace: ',', '.' }}",
      "priceCurrency": "{{ shop.currency }}",
      "itemCondition": "https://schema.org/NewCondition",
      "url": "{{ shop.secure_url }}{{ variant.url }}",
      "sku": "{{ variant.sku }}",
      "mpn": "{{ variant.barcode }}",
      "availability": "https://schema.org/{%- if variant.available -%}InStock{%- else -%}OutOfStock{%- endif -%}",
      "priceValidUntil": {{ "today" | date: '%s' | plus: 2592000 | date: "%Y-%m-%d" | json }},
      "customAttributes": {
        "strain": "{{ variant.metafields.custom.strain }}",
        "strainType": "{{ variant.metafields.custom.strain_type }}",
        "category": "{{ variant.metafields.custom.category }}",
        "strainGenetics": "{{ variant.metafields.custom.strain_genetics }}",
        "strainDescription": "{{ variant.metafields.custom.strain_description | strip_html }}",
        "thcPercentage": "{{ variant.metafields.custom.thc_percentage }}",
        "strainEffects": "{{ variant.metafields.custom.strain_effects }}",
        "thirdPartyTestResults": "{{ variant.metafields.custom.3rd_party_test_results }}"
      }
    }{%- if forloop.index < product.variants.size -%},{%- endif -%}
  {%- endfor -%}
]

 

:

The issue I'm encountering is that Google's Rich Results Test either fails to recognize multiple variants or shows only one variant without detecting any of the added metafields (customAttributes).

What am I doing wrong in incorporating these variant metafields in the JSON-LD? Is there a specific format or practice that ensures variant-specific data is properly picked up by Google's schema validation tools? Any insight or best practices for handling variant metafields in Shopify JSON-LD would be greatly appreciated.

Thanks in advance for any help!

Reply 1 (1)

Hey_Jak
Shopify Partner
131 9 25

Give it a try: https://feedarmy.com/kb/shopify-microdata-for-google-shopping/

❤️ Buy me a coffee
- Check my youtube: Hey Jak
Was your question answered? Mark it as an Accepted Solution.