Skip to content

Instantly share code, notes, and snippets.

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 iWebbers/48e8113c7abdb543eb02b661c0eb856a to your computer and use it in GitHub Desktop.
Save iWebbers/48e8113c7abdb543eb02b661c0eb856a to your computer and use it in GitHub Desktop.
global $product;
$sd_product_name = $product->get_title();
$sd_product_image = get_the_post_thumbnail_url();
$sd_product_description = substr(wp_strip_all_tags($product->get_post_data()->post_excerpt),0,107) . '...';
$sd_product_sku = $product->get_sku();
$sd_product_rating_value = $product->get_average_rating();
$sd_product_rating_count = $product->get_rating_count();
$sd_product_currency = get_woocommerce_currency();
$sd_product_price = $product->get_price();
$sd_product_stock = $product->get_stock_status();
$sd_organization = get_bloginfo('name');
echo '
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "' . $sd_product_name . '",
"image": [
"' . $sd_product_image . '"
],
"description": "' . $sd_product_description . '",
"sku": "' . $sd_product_sku . '",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "' . $sd_product_rating_value . '",
"reviewCount": "' . $sd_product_rating_count . '"
},
"offers": {
"@type": "Offer",
"priceCurrency": "' . $sd_product_currency . '",
"price": "' . $sd_product_price . '",
"availability": "http://schema.org/' . $sd_product_stock . '",
"seller": {
"@type": "Organization",
"name": "' . $sd_organization . '"
}
}
}
</script>
';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment