Skip to content

Instantly share code, notes, and snippets.

@daveloodts
Last active August 20, 2021 21:07
Show Gist options
  • Save daveloodts/46a7e7bb67e3c01e2bcc23de728cfbff to your computer and use it in GitHub Desktop.
Save daveloodts/46a7e7bb67e3c01e2bcc23de728cfbff to your computer and use it in GitHub Desktop.
schema.org book for WooCommerce
<?php
// define the woocommerce_structured_data_product callback
function filter_woocommerce_structured_data_product( $markup, $product ) {
$formaat = get_field("boek_formaat");
$authors = get_field("boek_auteurs");
$date = get_the_date('Y m d');
$markup['additionalType'] = "book";
$markup['brand'] = "Ertsberg";
$markup['isbn'] = $product->get_sku();
$markup['author'] = ['@type' => 'Person', 'name' => $authors];
$markup['datePublished'] = $date;
$markup['inLanguage'] = "nl-BE";
$markup['copyrightHolder'] = ['@type' => 'Organisation', 'name' => 'Erstberg'];
$markup['publisher'] = ['@type' => 'Organisation', 'name' => 'Erstberg'];
$markup['bookFormat'] = $formaat;
return $markup;
};
// add the filter
add_filter( 'woocommerce_structured_data_product', 'filter_woocommerce_structured_data_product', 10, 2 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment