Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Structured Data for WooCommerce: Keep Google happy by providing product info in a form it can easily read https://www.damiencarbery.com/2019/04/google-structured-data-for-woocommerce/
<?php
/*
Plugin Name: Google Structured Data for WooCommerce
Plugin URI: https://www.damiencarbery.com/2019/04/google-structured-data-for-woocommerce/
Description: Add Google Structured Data to WooCommerce products. Asked in: https://www.facebook.com/groups/genesiswp/permalink/2358845040833346/
Author: Damien Carbery
Version: 0.1
*/
add_action( 'woocommerce_before_single_product_summary', 'dcwd_add_wc_structured_data' );
function dcwd_add_wc_structured_data() {
$product = wc_get_product( get_the_ID() );
?>
<!-- JSON-LD markup generated by Google Structured Data Markup Helper. -->
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Product",
"name" : "<?php echo $product->get_name(); ?>",
"image" : "<?php echo get_the_post_thumbnail_url( $product->get_id(), 'full' ); ?>",
"description" : "<?php echo $product->get_short_description(); ?>",
"brand" : {
"@type" : "Brand",
"name" : "<?php echo $product->get_name(); ?>"
},
"offers" : {
"@type" : "Offer",
"price" : "<?php echo $product->get_price(); ?>"
}
}
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.