WC_Product::is_viewable │ public │ WC 11.1.0

Whether the current user can view this product: it is published, or they can edit it. A variation additionally requires its parent product to be viewable.

Method of the class: WC_Product{}

No Hooks.

Returns

bool.

Usage

$WC_Product = new WC_Product();
$WC_Product->is_viewable();

Changelog

Since 11.1.0 Introduced.

WC_Product::is_viewable() code WC 11.3.0

public function is_viewable() {
	$parent_id          = $this->get_parent_id();
	$has_product_parent = $parent_id && in_array( get_post_type( $parent_id ), array( 'product', 'product_variation' ), true );

	return ( ProductStatus::PUBLISH === $this->get_status() || current_user_can( 'edit_post', $this->get_id() ) )
		&& ( ! $has_product_parent || ProductStatus::PUBLISH === get_post_status( $parent_id ) || current_user_can( 'edit_post', $parent_id ) );
}