Last active
April 28, 2023 08:34
-
-
Save mattiasghodsian/4dcf3995b0df60757afeca8bbaf3f9a4 to your computer and use it in GitHub Desktop.
[WooCommerce] Add missing Schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Title: Add missing Schema WooCommerce | |
* Author: Mattias Ghodsian | |
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
**/ | |
function woo_missing_schema_fields($data) { | |
global $product; | |
$images = $product->get_gallery_image_ids(); | |
$data['brand'] = "Festmäklarna"; | |
$data['aggregateRating'] = [ | |
"ratingValue" => ( $product->get_average_rating() ? $product->get_average_rating() : '3.0'), | |
"reviewCount" => ( $product->get_review_count() ? $product->get_review_count() : '1') | |
]; | |
// $data['gtin8'] = ""; // gtin8, gtin12, gtin13, gtin14, mpn, isbn | |
if ( ! ( $images ) ) { | |
$data['image'] = get_site_url()."/wp-content/uploads/images/ingen_bild.png"; | |
}else{ | |
$data['image'] = wp_get_attachment_image_src( $images[0], 'full' )[0]; | |
} | |
return $data; | |
} | |
add_filter( 'woocommerce_structured_data_product', 'woo_missing_schema_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment