WC_Brands::hook_product_brand_block
Hooks the product brand terms block into single product templates.
Method of the class: WC_Brands{}
No Hooks.
Returns
Array. The array of hooked block types.
Usage
$WC_Brands = new WC_Brands(); $WC_Brands->hook_product_brand_block( $hooked_block_types, $relative_position, $anchor_block_type, $context );
- $hooked_block_types(array) (required)
- The array of hooked block types.
- $relative_position(int) (required)
- The relative position of the hooked block.
- $anchor_block_type(string) (required)
- The type of anchor block.
- $context(WP_Block_Template) (required)
- The context of the block.
WC_Brands::hook_product_brand_block() WC Brands::hook product brand block code WC 10.4.3
public function hook_product_brand_block( $hooked_block_types, $relative_position, $anchor_block_type, $context ) {
// Only add the block as the last child of the product meta block
if ( 'woocommerce/product-meta' === $anchor_block_type &&
'last_child' === $relative_position &&
$context instanceof WP_Block_Template &&
'single-product' === $context->slug ) {
remove_action( 'woocommerce_product_meta_end', array( $this, 'show_brand' ) );
// Check if the template already has a product brand block
if ( ! $this->template_already_has_brand_block( $context ) ) {
// Simply add the core/post-terms block type
$hooked_block_types[] = 'core/post-terms';
}
}
return $hooked_block_types;
}