WC_Brands::add_structured_datapublicWC 1.0

Add structured data to product page.

Method of the class: WC_Brands{}

No Hooks.

Returns

Array. $markup

Usage

$WC_Brands = new WC_Brands();
$WC_Brands->add_structured_data( $markup );
$markup(array) (required)
Markup.

WC_Brands::add_structured_data() code WC 10.5.0

public function add_structured_data( $markup ) {
	global $post;

	if ( ! is_array( $markup ) ) {
		$markup = array();
	}

	if ( array_key_exists( 'brand', $markup ) ) {
		return $markup;
	}

	$brands = get_the_terms( $post->ID, 'product_brand' );

	if ( ! empty( $brands ) && is_array( $brands ) ) {
		// Can only return one brand, so pick the first.
		$brand_thumbnail = wc_get_brand_thumbnail_url( $brands[0]->term_id, 'full' );
		$markup['brand'] = array(
			'@type' => 'Brand',
			'name'  => $brands[0]->name,
		);
		if ( $brand_thumbnail ) {
			$markup['brand']['logo'] = $brand_thumbnail;
		}
	}

	return $markup;
}