WooCommerce & Schema.org Is Awesome
Adding schema.org markup to a well coded WordPress theme is relatively straight forward and doesn’t take very long to get setup.
I covered how to add schema.org markup to your WordPress theme in a previous post, but I recently needed to apply schema.org markup to an e-commerce site using WooCommerce.
It’s surprisingly easy to do. You’ll need to be using a child theme for the steps that follow.
1. Setup the necessary function in the functions.php file for your theme
Add the following to your functions.php file. It creates a custom function, schema_org_markup
.
function schema_org_markup() { $schema = 'http://schema.org/'; // Is single post if ( function_exists(is_woocommerce) && is_woocommerce() ) { $type = 'Product'; } elseif ( is_single() ) { $type = "Article"; } else { if ( is_page( 644 ) ) { // Contact form page ID $type = 'ContactPage'; } // Is author page elseif ( is_author() ) { $type = 'ProfilePage'; } // Is search results page elseif ( is_search() ) { $type = 'SearchResultsPage'; } // Is of movie post type elseif ( is_singular( 'movies' ) ) { $type = 'Movie'; } // Is of book post type elseif ( is_singular( 'books' ) ) { $type = 'Book'; } else { $type = 'WebPage'; } } echo 'itemscope="itemscope" itemtype="' . $schema . $type . '"'; }
2. Call schema_org_markup() In Your Header
Open up the header.php file for your child theme and find the html
tag, usually towards the top. You’ll want to call the schema_org_markup
function inside that html
tag, like so:
<html <?php schema_org_markup(); ?> <?php language_attributes(); ?>>
3. Create a WooCommerce template file in your child theme
Create a directory in your child theme folder named woocommerce. Inside the woocommerce folder, create another new folder named single-product. Inside the single-product folder, create a file named price.php. The contents of your price.php file should look like this:
<?php /** * Single Product Price, including microdata for SEO * * @author WooThemes * @package WooCommerce/Templates * @version 1.6.4 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $post, $product; ?> <div itemprop="offers" itemscope itemtype="http://schema.org/Offer"> <p class="price"><?php echo $product->get_price_html(); ?></p> <meta itemprop="name" content="<?php echo $product->get_name(); ?>" /> <meta itemprop="price" content="<?php echo $product->get_price(); ?>" /> <meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" /> <link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" /> </div>
4. All Done
That’s all that’s required to add schema.org markup to individual WooCommerce product pages. Pretty simple.
If you run into any issues or it doesn’t seem to be working for you, let me know. I’ve only tested this with two themes, Vantage and Virtue. Remember, this only works with well-crafted WordPress themes. Doing this with purchased themes from ThemeForest or other paid theme marketplaces can be significantly more difficult.
Comments are open so let me know if you have any issues, additions, questions, or suggestions.
Well, now what?
Work with Me
I'm available for hire and always taking new clients, big and small. Got a project or an idea you'd like to discuss? Startup plan but no developer to make it happen? Just get in touch, I'd love to see if I can help you out!
Leave some Feedback
Got a question or some updated information releavant to this post? Please, leave a comment! The comments are a great way to get help, I read them all and reply to nearly every comment. Let's talk. š
Longren.io is proudly hosted by DigitalOcean

Just what I was looking for! Can we add schema for reviews as well?
Yes:
https://schema.org/Review
Tyler, thanks for the walk-through.
Nice – could make an ez plugin for this…
Hi thanks for the trick, but I still not have tag name on structured data, my site is http://www.herbashop.it
Hi Omar,
How did you add the schema markup? I don’t see any schema markup on your site at all (unless you’ve since removed it).
If you’d like help setting it up, email me at tyler@longren.io or tlongren@gmail.com.
Hi there!
I’d be happy to lend a hand. Would take some additional modifications to the code in this tutorial, but Schema.org has many properties available for use with reviews.
Email me at tyler@longren.io or tlongren@gmail.com if you want help or have more questions.
Parse error: syntax error, unexpected ‘function’ (T_FUNCTION), expecting ‘{‘ in /home/digilzcr/public_html/wp-content/themes/vantage/functions.php on line 451
What does this mean? I used the exact code as above in point 1
Thank-you sir!
How would these work for adding markup to product variations?
Hi Tyler, great article, one of only a few out there so thank you. I have added the above code to my Woocommerce site which is using WooThemes Canvas theme but for some reason the itemtype for all my test products is being set to ‘Article’ rather than ‘Product’. Category and Shop pages are being set to correctly Product itemtype. Example product url is http://www littletigertest co uk/product/les-papoum-elephant-soft-toy-moulin-roty-copy/
I know you must be busy so I am just chancing my luck for a reply š
Thanks Steve.
Hey Steve, ever get it working? If not I’d be happy to have a look. Let me know.
Hi Tyler, thanks for responding, the WooThemes Canvas theme I am using does this out of the box. Adding the extra code simply broke it!
I should have checked first before assuming it did not.
Thanks
Good to know! Seems like more and more themes are integrating schema.org markup, especially the WooThemes folks.
Slight correction to your code required as it’s defaulting WooCommerce products to articles.
Otherwise working great.
Interesting!!
Really appreciate you bringing this up.
I’ll have a major revision ready within a few weeks hopefully that will let you fill woocommerce with all the microdata you could want (that may be a bit of an exaggeration, but I’ll be taking feature requests).
I may have said too much already, keep an eye out.
Martin, I’ll update the post with your properly working code momentarily.
LOL… Your mistake was “I’ll be taking feature requests” (watches the inbox explode!) š
Glad it was useful and definitely be interested to see what developments are in the wind. I’m looking at how to incorporate in volume discount data (max/min price) and multi-currency information based on the Aelia currency switcher plugin so got a bit list of “would be nice” to incorporate in..
Let me know if you need a critical eye to cast over any dev code…
Can this code be adapted to work with WP E-Commerce? or is there a plugin or script that you can recommend for WPEC? Thank you!
Absolutely. There’s no plugin I can recommend for WPEC. I’d be willing to develop something. I’d need access to a demo WPEC site though for testing, would just make things so much faster if I didn’t have to setup WPEC with products and everything.
Do you happen to have a site using WPEC that I could have access to? Or would you be willing to set one up?
Why can’t you just filter the default schema like you can in Genesis?
Tyler, love that you have enabled people to add this themselves. For people who just want it done, and comprehensively so you get the best results from your search results, check out the WordPress Plugin made by Schema Apps – https://www.schemaapp.com/product/schema-app-woocommerce/
Tyler. Thanks for this information as it is very informative. I have a small question. I currently have a site that is using WooCommerce and the theme from WooThemes seems to have most of the schema.org product tags. However, it does not have “itemcondition”. Is there as way you can think of that I can simply add only the itemcondition schema?
7.27 New
did we ever get a fix for itemcondition and woocommerce for google merchant validation?
It works perfectly! Thank you so much! This article really made my day! Thank you thank you thank you!
Hi, many thanks for the easy walk through! I am getting an error from Google Webmaster though as all my category pages are being marked up as ‘product’ pages with no name. I’m using the Storefront theme. Any ideas what needs to be changed? Thanks, Iain
Hey
I found your blog through woocommerce, and their post about selling digital goods.
If you could help me solve a problem, or suggest a solution, it would be amazing.
I have a website built on WordPress, and Woocommerce.
It sells a digital / printed magazine. Whihc means, that the same magazine issue can be bought in printed and online versions.
But, we want to sell the digital version in “Zinio” format”, which means, that the licence a person bought, would allow them to read the magazine online, on their pc, laptop, smartphone, tablet, without dowloading it to their computer. To prevent them from sharing the pdf file of the magazine.
is this possible on WooCommerce?
With best wishes, thank you, Martyna
I’d like to display our products as Rich Cards on Googles search result pages but for that you need more structured data. My products are missing the values for “brand” and the “MPN”. Do you know a solution how to echo such values when you use an additional product attribute “brand” in Woocommerce?
Here you find more informations about the markup for rich cards: https://developers.google.com/search/docs/guides/search-gallery
It implemented the scheme but getting name error, is there any pice of code i have to add ? I have woocommerece store photosquare.in
Doesn’t work with Divi’s latest version in 2019
Greetings!
I’ve been looking for a long time for a working code, so I finally found it.
There is nothing suitable on the Russian Internet.
Thank you!
Thank you for this post Tyler. I am not sure if you read these comments any longer, but I am hoping one day you might.
Our website was created with WordPress/Woocommerce and up to July last year, it had product schema markup showing on Google searches, with the price of the products and also “in stock”. IT showed in all google organic searches, it was fabulous.
Then it vanished. No more price showing, just a standard search listing. This has definitely had a bad effect on our sales, so I have been ever since trying to figure out what to do to bring the rich snippets back.
I spent many sleepless nights researching and trying, I paid 2 developers and nobody could never do it.
Then I found this post and followed all the necessary steps.
This was about 4 days ago.I now can see the structure mark up on some products when I do a search, like 4 products out of 200, but at least I can see it there. I have no idea why that is, why is it not showing on all products when they come up on searches? And why is it showing on these? It is bizarre.
I would be happy to hire your services for a few hours to try and figure this out and fix it once and for all.
You can contact me via our website https://ww.shop4safety.com.au
Thanks again,
Luciana
Hi thanks for the trick, but I still not have tag name on structured data, my site is http://www.hlifeweb.it
Cant you do only step 3?
Thanks for the info. I was looking at how to add in product schema like brands without installing a plugin and trying to code it in my Wordprress Woocommerce website. My website using twenty twenty theme. Will your schema code apply? My website is https://theholythead.com
sorry i tried to click on the previous link but it doesn’t work. the revised link is https://theholythread.com/
Great! I really appreciate your article on Email Marketing. I am extremely glad to peruse your articles it’s helpful for me also I am totally happy with your site
thanks for sharing it with us