Home Forums WoodMart support forum Woodmart Brand adding via Attributes has issue for Structured data Reply To: Woodmart Brand adding via Attributes has issue for Structured data

#221238

benrich
Participant

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