WooCommerce
WooCommerce Product, Offer and AggregateRating JSON-LD Done Right
Product, Offer and AggregateRating JSON-LD for WooCommerce is how you describe a product's price, availability and genuine ratings to search and answer engines in a form they can parse. In my builds at webdev-saif.com I emit one Product node per purchasable product from WC_Product data, attach a single Offer with the current price and schema.org availability URL, and add AggregateRating only when real approved reviews exist.
What Product, Offer and AggregateRating JSON-LD actually does
Product, Offer and AggregateRating JSON-LD turns a WooCommerce product page into a self-describing record. The Product node says what the item is; the Offer node says what it costs right now and whether it can be bought; AggregateRating summarises verified ratings and review counts. Search engines use these fields for product and review snippets, and answer engines use them to quote a price or availability statement with confidence. I keep the three nodes tied to the same product ID so the markup cannot drift from the rendered page. If a field is not visible to a visitor, I do not put it in the graph.
- Product: name, image, description, sku, brand and identifier
- Offer: price, priceCurrency, availability, url and itemCondition
- AggregateRating: ratingValue, ratingCount and reviewCount
- Review: individual approved comments with author and datePublished
Build the Product node from WC_Product, not from the template
Read everything from the WC_Product object, not from the template markup. In a custom theme I call wc_get_product() inside a wp_head callback on single product pages, then use get_name(), get_description(), get_sku(), get_permalink() and get_image_id() with wp_get_attachment_image_src(). For the graph @id I use the product permalink with a #product fragment, and I reuse the site Organization @id as the Offer seller so the nodes connect. I encode with wp_json_encode() and JSON_UNESCAPED_SLASHES plus JSON_UNESCAPED_UNICODE, never by concatenating strings. That avoids broken JSON when a product title contains a quote or an ampersand.
- wc_get_product() as the single source of truth
- get_name(), get_description(), get_sku() and get_permalink()
- wp_get_attachment_image_src() for an absolute image URL
- wp_json_encode() with JSON_UNESCAPED_SLASHES
- A stable @id from the product permalink plus #product
Price and availability rules that keep Offer valid
The Offer must describe the price a buyer can actually pay today. I use get_price(), not get_regular_price(), because get_price() returns the active sale price in WooCommerce. Price is a plain number with a dot decimal separator and no currency symbol or thousands separator. priceCurrency is the ISO 4217 code, for example BDT or USD. Map get_stock_status() to an absolute schema.org URL: InStock, OutOfStock, OnBackorder to BackOrder, and PreOrder when pre-orders are enabled. Add priceValidUntil only when the sale has a known end date; omit it otherwise. Declare itemCondition as NewCondition, UsedCondition or RefurbishedCondition rather than leaving it blank.
- get_price() gives the current effective price
- priceCurrency uses ISO 4217 codes such as BDT
- Availability values are schema.org URLs, not bare words
- priceValidUntil only with a known sale end date
- itemCondition from NewCondition, UsedCondition or RefurbishedCondition
Variable products and the one-Offer-per-URL rule
Variable products are where most product markup goes wrong. A parent product has no single price, so emitting one Offer with get_price() can describe a price no variation sells for. If each variation has a stable URL, I emit one Product node per variation with its own sku, image, price and availability. If variations only differ by query parameters, I describe the parent with get_variation_prices() as a minimum and maximum priceSpecification range, and I do not claim a specific availability for every option. I never mark up an out-of-stock variation as purchasable just because the parent is in stock.
- One Product node per variation when the URL is stable
- get_available_variations() for sku, price and stock per variation
- A price range for parents without a fixed URL per option
- Never inherit parent availability for an out-of-stock variation
Honest AggregateRating and Review markup
Review markup is a trust contract, so I only mark up reviews that WooCommerce actually approved and that came from a real purchaser. I check wc_review_ratings_enabled() and get_comments() with type review and status approve, then read get_average_rating() and get_rating_count() from the product. AggregateRating uses ratingValue, ratingCount, reviewCount, bestRating 5 and worstRating 1. A rating with zero reviews gets no AggregateRating node at all. Each Review node includes author, datePublished, reviewRating and the visible reviewBody. I do not write testimonials myself, edit customer words, or copy vendor ratings onto my own store.
- get_comments() with type review and status approve
- get_average_rating() and get_rating_count() from WC_Product
- bestRating 5 and worstRating 1 on every AggregateRating
- No AggregateRating when reviewCount is zero
- Review nodes only for visible, approved customer text
Where to output the markup and how to cache it
I output one JSON-LD script in wp_head so the markup is in the initial HTML, not injected later by a script loader or tag manager. Structured data that depends on live price and stock must be generated on the server at request time. To keep it cheap, I cache the encoded graph in a transient keyed by product ID and invalidate it on woocommerce_product_object_updated_props, transition_comment_status and completed order hooks. In my WooCommerce builds the cache lives beside the product data source, so a price change and its markup change in the same deployment.
- Render in wp_head on is_product() only
- Cache the encoded graph per product ID
- Purge on product update, review approval and order completion
- Avoid page-builder wrappers around the script tag
Verify the graph, then set expectations
Validation is not optional because Google ignores malformed markup. I test a representative simple product, a sale product, a variable product and a product with reviews in the Rich Results Test, then check the same URLs in validator.schema.org for syntax. I watch Search Console product and review snippet reports for warnings about missing price, invalid availability or mismatched ratings. Rich result display is never guaranteed: correct JSON-LD makes a page eligible, it does not force a snippet. I am Saif Al Jahan, a WordPress and PHP developer in Mymensingh, Bangladesh, and I treat the markup as an accuracy layer, not a ranking trick.
- Rich Results Test on four product types
- validator.schema.org for JSON-LD syntax
- Search Console enhancement reports for coverage and warnings
- No guaranteed rich result from valid schema alone
Frequently asked questions
What is Product schema in WooCommerce?
Product schema is JSON-LD that describes a single item using schema.org terms such as name, image, sku, brand and identifier. In WooCommerce I generate it from the WC_Product object so the markup always matches the visible page. It gives search and answer engines a clean record of what you sell, independent of the theme HTML.
Should the Offer price be the regular price or the sale price?
Use the current price a buyer would pay, which wc_get_product()->get_price() returns. That means the sale price during a promotion. Keep priceCurrency as an ISO 4217 code, use a dot decimal separator with no symbol or commas, and add priceValidUntil only when the promotion has a known end date.
How should I mark up availability for out-of-stock products?
Map WooCommerce stock status to a full schema.org URL: InStock, OutOfStock, BackOrder for on backorder, and PreOrder when pre-orders are enabled. Do not use plain words or numeric codes. Keep the Offer on the page even when out of stock; just set availability to OutOfStock and leave the price intact.
Can I add AggregateRating if I have no reviews?
No. An AggregateRating with ratingValue but no reviewCount is misleading and can trigger a Search Console warning. I only emit the node when WooCommerce has approved reviews and get_rating_count() is greater than zero. Each rating must come from a real customer review that is visible on the page, with bestRating 5 and worstRating 1.
How do I handle variable products in product schema?
If every variation has a stable URL, emit one Product and Offer per variation with its own sku, price and availability. If variations are only query parameters, describe the parent and use a price range from get_variation_prices() instead of claiming one exact price. Never copy parent availability onto a variation that is out of stock.