WC_Product_Variation_Data_Store_CPT::update_visibility()
Update visibility terms based on props.
Method of the class: WC_Product_Variation_Data_Store_CPT{}
No Hooks.
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->update_visibility( $product, $force );
- $product(WC_Product) (required) (passed by reference — &)
- Product object.
- $force(true|false)
- Force update. Used during create.
Default: false
Changelog
Since 3.0.0 | Introduced. |
WC_Product_Variation_Data_Store_CPT::update_visibility() WC Product Variation Data Store CPT::update visibility code WC 9.2.3
protected function update_visibility( &$product, $force = false ) { $changes = $product->get_changes(); if ( $force || array_intersect( array( 'stock_status' ), array_keys( $changes ) ) ) { $terms = array(); if ( 'outofstock' === $product->get_stock_status() ) { $terms[] = 'outofstock'; } wp_set_post_terms( $product->get_id(), $terms, 'product_visibility', false ); } }