WC_Product_Data_Store_CPT::read_visibility()
Convert visibility terms to props. Catalog visibility valid values are 'visible', 'catalog', 'search', and 'hidden'.
Method of the class: WC_Product_Data_Store_CPT{}
No Hooks.
Return
null
. Nothing (null).
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. |
WC_Product_Data_Store_CPT::read_visibility() WC Product Data Store CPT::read visibility code WC 9.4.2
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, ) ); }