Skip to content

Instantly share code, notes, and snippets.

@GauravKhupse
Last active June 30, 2022 11:41
Show Gist options
  • Save GauravKhupse/6f90e6a9499662382b905f2fe558ea18 to your computer and use it in GitHub Desktop.
Save GauravKhupse/6f90e6a9499662382b905f2fe558ea18 to your computer and use it in GitHub Desktop.
Added compatibility YITH WooCommerce Brands Add-on Premium for brand field.
add_filter( 'wp_schema_pro_schema_product', 'my_brand_field_mapping', 10, 3 );
/**
* Mapping extra field for schema markup.
*
* @param array $schema Schema array.
* @param array $data Mapping fields array.
* @return array
*/
function my_brand_field_mapping( $schema, $data, $post ) {
$product_id = get_the_id();
$product = wc_get_product( $product_id );
$taxonomy = 'yith_product_brand';
$brand_names = wp_get_post_terms( $product_id, $taxonomy, array( 'fields' => 'names' ) );
// Get the brand name
// $brand_name = reset( $brand_names );
foreach( $brand_names as $key => $brand ) {
if ( isset( $brand ) && ! empty( $brand ) ) {
$schema['brand'][$key]['name'] = esc_html( wp_strip_all_tags( $brand ) );
}
}
return $schema;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment