[Hook] Add Product Schema Markup on WooCommerce Products

With this snippet you will be able to add manually without using a plugin product schema on your WooCommerce Products automatically . Just copy and paste the following Code to your child theme.

Don’t forget to change the currency symbol and the Organisation name

function voodal_product_schema() {
	global $woocommerce;
	
	if(is_product())
	{
		global $product;
		$brand="";
		$brands = wp_get_post_terms( $product->get_id(), 'product_brand', array("fields" => "all") );
    foreach( $brands as $brand ) {
       $brand= $brand->name; 
		break;
    }
		$image = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'single-post-thumbnail' );
	?>
<script type="application/ld+json">
{
  "@context": "https://schema.org/",
  "@type": "Product",
  "name": "<?php echo $product->get_title(); ?>",
  "image": [
    "<?php echo $image[0]; ?>"
   ],
  "description": "<?php echo strip_tags(get_post($product->get_id())->post_content); ?>",
  "sku": "<?php echo $product->get_sku(); ?>",
  "mpn": "<?php echo $product->get_sku(); ?>",
  "brand": {
    "@type": "Thing",
    "name": "<?php echo $brand; ?>"
  },
  "review": {
    "@type": "Review",
    "reviewRating": {
      "@type": "Rating",
      "ratingValue": "5",
      "bestRating": "5"
    },
    "author": {
      "@type": "Organization",
      "name": "Your Organisation"
    }
  },
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "4.9",
    "reviewCount": "89"
  },
  "offers": {
    "@type": "Offer",
    "url": "<?php echo get_permalink($product->get_id()); ?>",
    "priceCurrency": "EUR",
    "price": "<?php echo $product->get_price(); ?>",
    "priceValidUntil": "2030-11-05",
    "itemCondition": "https://schema.org/NewCondition",
    "availability": "https://schema.org/InStock",
    "seller": {
      "@type": "Organization",
      "name": "Your Organisation"
    }
  }
}
</script>

<?php
	}
}
add_action( 'wp_head', 'voodal_product_schema' );

Leave a Reply

Your email address will not be published. Required fields are marked *

In Web Development, WordPress

How to Create a WebSite with WordPress (Step By Step)

Step by Step Guide to create a website with WordPress . Words like WordPress , Hosting , Blogging sounds a bit unfamiliar to your, right? On this post we will break down all the steps you have to follow to build your own website without required from you to have any coding skills or web […]

Read More

In Hosting, WordPress

What WordPress Hosting to Choose – (2019 Guide) – Comparison

Are you currently searching for a reliable hosting provider for your WordPress site or you are starting a new website and don’t know what hosting plan and provider to choose? If yes, continue reading, as we will analyze some of the most popular hosting providers. And you will be able to make the correct choice […]

Read More

In AMP, SEO, Web Development, WordPress

Create Custom AMP for your WordPress News Site

Nowadays more and more News Sites start using the new AMP technology on their websites to gain more speed and more traffic from Google Search as Google seems to prefer AMP Powered websites and you will be able to get better positions if you are able to serve an AMP Version of your page. On […]

Read More