WC_Tracker::get_block_tracker_data()public staticWC 1.0

Get tracker data for a specific block type on a woocommerce page.

Method of the class: WC_Tracker{}

No Hooks.

Return

Array. Associative array of tracker data with keys:

  • page_contains_block
  • block_attributes

Usage

$result = WC_Tracker::get_block_tracker_data( $block_name, $woo_page_name );
$block_name(string) (required)
The name (id) of a block, e.g. woocommerce/cart.
$woo_page_name(string) (required)
The woo page to search, e.g. cart.

WC_Tracker::get_block_tracker_data() code WC 8.6.1

public static function get_block_tracker_data( $block_name, $woo_page_name ) {
	$blocks = WC_Blocks_Utils::get_blocks_from_page( $block_name, $woo_page_name );

	$block_present = false;
	$attributes    = array();
	if ( $blocks && count( $blocks ) ) {
		// Return any customised attributes from the first block.
		$block_present = true;
		$attributes    = $blocks[0]['attrs'];
	}

	return array(
		'page_contains_block' => $block_present ? 'Yes' : 'No',
		'block_attributes'    => $attributes,
	);
}