Automattic\WooCommerce\Blocks\BlockTypes

FeaturedCategory::get_itemprotectedWC 1.0

Returns the featured category.

Method of the class: FeaturedCategory{}

No Hooks.

Returns

\WP_Term|null.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_item( $attributes );
$attributes(array) (required)
Block attributes.
Default: empty array

FeaturedCategory::get_item() code WC 9.8.5

protected function get_item( $attributes ) {
	$id = absint( $attributes['categoryId'] ?? 0 );

	$category = get_term( $id, 'product_cat' );
	if ( ! $category || is_wp_error( $category ) ) {
		return null;
	}

	return $category;
}