WordPress at Your Fingertips
function is not described

WC_Product_Data_Store_CPT::read_visibility() protected WC 3.0.0

Convert visibility terms to props. Catalog visibility valid values are 'visible', 'catalog', 'search', and 'hidden'.

{} It's a method of the class: WC_Product_Data_Store_CPT{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->read_visibility( $product );
$product(WC_Product) (required) (passed by reference — &)
Product object.

Changelog

Since 3.0.0 Introduced.

Code of WC_Product_Data_Store_CPT::read_visibility() WC 5.8.0

protected function read_visibility( &$product ) {
	$terms           = get_the_terms( $product->get_id(), 'product_visibility' );
	$term_names      = is_array( $terms ) ? wp_list_pluck( $terms, 'name' ) : array();
	$featured        = in_array( 'featured', $term_names, true );
	$exclude_search  = in_array( 'exclude-from-search', $term_names, true );
	$exclude_catalog = in_array( 'exclude-from-catalog', $term_names, true );

	if ( $exclude_search && $exclude_catalog ) {
		$catalog_visibility = 'hidden';
	} elseif ( $exclude_search ) {
		$catalog_visibility = 'catalog';
	} elseif ( $exclude_catalog ) {
		$catalog_visibility = 'search';
	} else {
		$catalog_visibility = 'visible';
	}

	$product->set_props(
		array(
			'featured'           => $featured,
			'catalog_visibility' => $catalog_visibility,
		)
	);
}