Merge pull request #15569 from woocommerce/fix/15566
Update variation outofstock term on save.
This commit is contained in:
commit
b2ce6212d4
|
@ -121,6 +121,7 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
||||||
|
|
||||||
$this->update_post_meta( $product, true );
|
$this->update_post_meta( $product, true );
|
||||||
$this->update_terms( $product, true );
|
$this->update_terms( $product, true );
|
||||||
|
$this->update_visibility( $product, true );
|
||||||
$this->update_attributes( $product, true );
|
$this->update_attributes( $product, true );
|
||||||
$this->handle_updated_props( $product );
|
$this->handle_updated_props( $product );
|
||||||
|
|
||||||
|
@ -185,6 +186,7 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
||||||
|
|
||||||
$this->update_post_meta( $product );
|
$this->update_post_meta( $product );
|
||||||
$this->update_terms( $product );
|
$this->update_terms( $product );
|
||||||
|
$this->update_visibility( $product, true );
|
||||||
$this->update_attributes( $product );
|
$this->update_attributes( $product );
|
||||||
$this->handle_updated_props( $product );
|
$this->handle_updated_props( $product );
|
||||||
|
|
||||||
|
@ -339,6 +341,28 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update visibility terms based on props.
|
||||||
|
*
|
||||||
|
* @since 3.0.0
|
||||||
|
*
|
||||||
|
* @param WC_Product $product
|
||||||
|
* @param bool $force Force update. Used during create.
|
||||||
|
*/
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update attribute meta values.
|
* Update attribute meta values.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue