WC_Tracker::get_block_tracker_data( string $block_name, string $woo_page_name )

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


Description Description


Parameters Parameters

$block_name

(Required) The name (id) of a block, e.g. woocommerce/cart.

$woo_page_name

(Required) The woo page to search, e.g. cart.


Top ↑

Return Return

(array) Associative array of tracker data with keys: - page_contains_block - block_attributes


Top ↑

Source Source

File: includes/class-wc-tracker.php

	public static function get_block_tracker_data( $block_name, $woo_page_name ) {
		$blocks = self::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,
		);
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.