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.
Returns
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 10.8.1
protected function update_visibility( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_intersect( array( 'stock_status' ), array_keys( $changes ) ) ) {
$terms = array();
if ( ProductStockStatus::OUT_OF_STOCK === $product->get_stock_status() ) {
$terms[] = ProductStockStatus::OUT_OF_STOCK;
}
wp_set_post_terms( $product->get_id(), $terms, 'product_visibility', false );
}
}