Woodmart Brand adding via Attributes has issue for Structured data
-
Google Structured DATA cant see Brands added via Attributes .
Why?
What is the solution ?
Hi,
Please, describe to us your problems in a bit more details. Attach some screenshots and provide us with a list of steps on how to reproduce it on your website. Have you tested how it works with a standard WordPress theme since this functionality is related to WooCommerce?
Thank you in advance.
I assume he/she’s talking about
<script type="application/ld+json">
{
@type: "Product",
etc etc etc
}
</script>
It’s missing the brand.
I too would like to see this added.
This functionality is a part of the WooCommerce plugin and our theme doesn’t influence this. You can check with a default WordPress theme.
This was my eventual implementation. It adds brand and all the gallery images.
add_filter( 'woocommerce_structured_data_product', function( $markup, $product ) {
// add Brand
if($brand = $product->get_attribute( 'pa_brand' )) {
$markup['brand'] = $brand;
}
// product gallery images
if($attachment_ids = $product->get_gallery_image_ids()) {
$gallery_images = array($markup['image']);
foreach( $attachment_ids as $attachment_id ) {
$gallery_images[] = wp_get_attachment_url( $attachment_id );
}
$markup['image'] = $gallery_images;
}
return $markup;
}, 10, 2 );
If others find it useful
Thank you very much for sharing your solution here.