Automattic\WooCommerce\Blocks\BlockTypes

FeaturedProduct::get_item │ protected │ WC 1.0

Returns the featured product.

Method of the class: FeaturedProduct{}

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

FeaturedProduct::get_item() code WC 11.1.2

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

	$product = wc_get_product( $id );
	if ( ! $product || ! $product->is_viewable() ) {
		return null;
	}

	return $product;
}