Skip to content

Instantly share code, notes, and snippets.

@Auke1810
Created February 15, 2018 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Auke1810/c92f66e6870b58cfe3e51349a59a9c54 to your computer and use it in GitHub Desktop.
Save Auke1810/c92f66e6870b58cfe3e51349a59a9c54 to your computer and use it in GitHub Desktop.
Easily add the correct structured data using Microdata for Google Merchant, this includes the missing microdata for condition. At the bottom of the header simple add the code below
<?php $meta = get_post_meta(get_the_ID());?>
<?php if (isset($product)){ ?>
<div itemscope itemtype="http://schema.org/Product">
<meta itemprop="name" content="<?php echo get_the_title(get_the_ID()); ?>">
<meta itemprop="productID" content="<?php echo get_the_ID(); ?>">
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<meta itemprop="price" content="<?php echo get_post_meta( get_the_ID(), '_regular_price', true); ?>" />
<meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" />
<link itemprop="availability" href="http://schema.org/<?php echo $meta['_stock_status'][0] ? 'InStock' : 'OutOfStock'; ?>" />
<meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition" />
</div>
</div>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment