<?php
if (isset($product)){
$meta = get_post_meta(get_the_ID());
$_product = new WC_Product(get_the_ID());
if ($_product->regular_price!=NULL){
$price = $_product->regular_price;
}elseif ($_product->price!=NULL){
$price = $_product->price;
}
if ( ($price > $_product->sale_price) && ($_product->sale_price!=NULL) ){
$price = $_product->sale_price;
}
?>
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "<?php echo get_the_title(get_the_ID()); ?>",
"offers": {
"@type": "Offer",
"priceCurrency": "<?php echo get_woocommerce_currency(); ?>",
"price": "<?php echo $price; ?>",
"itemCondition" : "http://schema.org/NewCondition",
"availability" : "http://schema.org/<?php echo $meta['_stock_status'][0] ? 'InStock' : 'OutOfStock'; ?>"
}
}
</script>
<?php } ?>
{
"@context": "https://schema.org/",
"@type": "Product",
"name": "Executive Anvil",
"image": [
"https://example.com/photos/1x1/photo.jpg",
"https://example.com/photos/4x3/photo.jpg",
"https://example.com/photos/16x9/photo.jpg"
],
"description": "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height.",
"sku": "0446310786",
"mpn": "925872",
"brand": {
"@type": "Brand",
"name": "ACME"
},
"review": {
"@type": "Review",
"reviewRating": {
"@type": "Rating",
"ratingValue": "4",
"bestRating": "5"
},
"author": {
"@type": "Person",
"name": "Fred Benson"
}
},
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.4",
"reviewCount": "89"
},
"offers": {
"@type": "Offer",
"url": "https://example.com/anvil",
"priceCurrency": "USD",
"price": "119.99",
"priceValidUntil": "2020-11-20",
"itemCondition": "https://schema.org/UsedCondition",
"availability": "https://schema.org/InStock"
}
}