A
A
alexiusgrey2022-04-08 14:40:05
Search Engine Optimization
alexiusgrey, 2022-04-08 14:40:05

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 } ?>

Source

If this is not enough or wrong, then how is it right? How do you personally do it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question