I am trying to get my custom Shipping and Return Metafields to be recognized by Google for Rich Results/Google Shopping, but the structured data is failing the validation test.
I need the correct Liquid snippet to successfully map my metafields to the necessary Google Schema properties.
Details of the Issue
Goal: Add Shipping Details and Return Policy to my product’s JSON-LD Schema, and functions for all my product.
Code Location: I understand the code needs to be placed in the right block, but need to know if it should be put in main-product.liquid file? And the exact position is?
Failure: When I try to add the code myself, it fails Google’s Rich Results Test instantly, confirming the structure is incorrect.
Request for Code Could an experienced developer please provide the correct Liquid code snippet required to map the metafields to the JSON-LD?
Google doesn’t read metafields directly, it only reads the final JSON-LD. So you need to inject your metafields inside the existing Product schema, not in a separate script.
Where to put it:
Go to Online Store → Themes → … → Edit code
Search for: type="application/ld+json" and "@type": "Product"
In most themes this is in a snippet (e.g. snippets/product-schema.liquid) or at the bottom of main-product.liquid.
You want to edit that existing Product JSON-LD block and add shipping/returns inside the "offers" object.
Key points:
Replace custom.shipping_details / custom.return_policy_url with your actual metafield namespace + key.
Keep everything dynamic wrapped in | json to avoid invalid JSON.
Don’t create a separate partial schema with only shippingDetails, keep it inside the main Product schema.
After saving, run the page through Google’s Rich Results Test again; if it still fails, it’s almost always a missing/extra comma or a wrong metafield handle.
So you should be able to add your info like below.
Of course, the actual code for OfferShippingDetails you need to construct yourself.
Here it is referenced, but you can obviously inline it too.
Also, you can use “Custom liquid” section added to the product template, no need to edit theme code for this.
But for product schema with custom metafields, you’ll probably want to customize the Liquid yourself since every store’s metafields are different. Happy to help debug if you run into issues.
To add Shipping Details and Return Policy to your product’s JSON-LD Schema, you should place the Liquid code snippet in themain-product.liquidfile. Here is the correct Liquid code snippet to map your metafields to the necessary Google Schema properties:
Good question, so now adding to what Tim and others shared, since the most common reason metafield-based schema fails validation is the data type, not the structure.
Three things usually break it:
Number metafields stored as text. If your shipping_days metafield is “single line text” with value 5 days, validation fails because deliveryTime expects an integer. Either change the metafield type to integer, or force it with | times: 1 in Liquid.
Missing currency on shippingRate. Even for free shipping you need a full MonetaryAmount with value: 0 and currency. Empty object breaks it.
returnPolicyCategory must be a schema.org enum. Plain text like “30 day returns” fails. It has to be one of: MerchantReturnFiniteReturnWindow, MerchantReturnUnlimitedWindow, or MerchantReturnNotPermitted.
Working metafield-based code. Place inside your existing offers object in main-product.liquid (or in product-schema.liquid snippet if your theme separates it):
Replace custom.shipping_rate, custom.min_delivery_days, etc. with your actual metafield namespace and keys. Run through Google’s Rich Results Test after saving. If it still errors, it’s almost always one of the three things above or a stray comma.
If you’re managing this across hundreds of products with different shipping rules per region, the Liquid approach gets messy fast since you have to maintain it across theme updates.
I built Webrex AI SEO Schema (free plan available) which handles ShippingDetails and hasMerchantReturnPolicy automatically without theme edits, but for a single shipping policy across the catalog, the Liquid above works fine.