Answer the question
In order to leave comments, you need to log in
Schema markup for Woo - is this code enough for a product card?
Will information be pulled up in the search through such a code?
<?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 } ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question