Table of Contents
- Viewing generated structured data
- Customizing structured data using WooCommerce filters
- Generating product data in other places, e.g. archives
WooCommerce outputs structured data for products automatically. According to Google, in the context of your store, this markup is suitable for single product pages.
Note: Prior to 3.5.6, limited data was sometimes output to archives/categories. This is no longer the case; according to Google guidelines only visible data should be marked up, and archives that link out to individual pages should not be marked out. Issue ref, Docs.
The data that is marked up should be data already visible on your page.
The structured data on the page should describe the content of that page. You should not create blank or empty pages just to hold structured data; nor should you add structured data about information that is not visible to the user, even if the information is accurate.
The full guidelines on structured data are found here.
WooCommerce outputs structured data to the page in JSON+LD
format.
Viewing generated structured data
If you view the source of a product page, search for application/ld+json
. This holds structured data for all elements on the page. This may include breadcrumbs, products, and any other relevant structured data.
A product will look something like this:
{
"@context": "https:\/\/schema.org\/",
"@type": "Product",
"@id": "http:\/\/local.wordpress.test\/product\/wordpress-pennant\/#product",
"name": "WordPress Pennant",
"image": "http:\/\/local.wordpress.test\/wp-content\/uploads\/2019\/02\/pennant-1.jpg",
"description": "This is an external product.",
"sku": "wp-pennant",
"offers": [
{
"@type": "Offer",
"price": "11.05",
"priceSpecification": {
"price": "11.05",
"priceCurrency": "USD",
"valueAddedTaxIncluded": "true"
},
"priceCurrency": "USD",
"availability": "https:\/\/schema.org\/InStock",
"url": "http:\/\/local.wordpress.test\/product\/wordpress-pennant\/",
"seller": {
"@type": "Organization",
"name": "Test",
"url": "http:\/\/local.wordpress.test"
}
}
]
}
You can see parsed structured data by using the Google structured data testing tool. There you can either paste in the source code of your page, or provide a URL. It will list what structured data it finds.
Customizing structured data using WooCommerce filters
2 filters control the markup for products.
woocommerce_structured_data_product_offer
- Marks up prices as offers. The format of this varies depending on the product type. This filter passes an array of data for offers.woocommerce_structured_data_product
- Controls the full set of data for the product. This filter passes an array of data.
Adding extra data
The woocommerce_structured_data_product
passes all values which will be output as structured data. This filter can therefore be used to change or add values for your structured data.
For example, let's say wanted to use IDs for SKU since we didn't use SKU on a particular store. This code could be used:
add_filter( 'woocommerce_structured_data_product', function( $markup, $product ) {
$markup['sku'] = $product->get_id(); // Set sku to product id.
return $markup;
} );
The resulting markup would then include this value.
Generating product data in other places, e.g. archives
As noted earlier, structured data is no longer output on archives as it contradicts Google guidelines. If you do however want to have data generated on archives, you can use the following code:
add_action( 'woocommerce_shop_loop', array( wc()->structured_data, 'generate_product_data' ), 10 );
This tells WooCommerce to generate data for a product during a shop loop when the woocommerce_shop_loop
filter is triggered.
Contribution
- Set up development environment
- Our Git Flow
- SCSS and JS minification
- Naming conventions
- CSS SASS coding guidelines and naming conventions
- Critical Flows
- API Critical Flows
- String localisation guidelines
- Translating WooCommerce
- Deprecation in core
- Adding Actions and Filters
- Common Issues
- Writing high-quality testing instructions
Release Notes
- Release Testing Instructions
- 3.6.x notes/FAQ
- 2.6.x to 3.0.0 Developer Migration Notes
- Select2 fields not working in 3.0.x
- Thumbnail Image Regeneration in 3.3+
- Customizing image sizes in 3.3+
REST API and CLI
CRUD & Data Descriptions
- Database Description
- CRUD Objects in 3.0
- Order and Order Line Item Data
- Coupon Data
- Customer Data
- Product Data
- Data Stores
Internal APIs
Theming
- Enabling product gallery features (zoom, swipe, lightbox)
- Template File Guidelines for Devs and Theme Authors
Examples / Guides
WooCommerce is an open source commerce platform built for WordPress and lovingly crafted by Automattic and the WooCommerce community 💜. Come and work with us!