Automattic\WooCommerce\Blocks\BlockTypes
FeaturedProduct::get_item
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() FeaturedProduct::get item code WC 10.8.1
protected function get_item( $attributes ) {
$id = absint( $attributes['productId'] ?? 0 );
$product = wc_get_product( $id );
if ( ! $product || ( ProductStatus::PUBLISH !== $product->get_status() && ! current_user_can( 'read_product', $id ) ) ) {
return null;
}
return $product;
}