Merge pull request #2008 from warrendholmes/master
- Make sure product has categories/tags when updating stock status.
This commit is contained in:
commit
2630b2f4a8
|
@ -2008,18 +2008,26 @@ function _woocommerce_term_recount( $terms, $taxonomy, $callback = true, $terms_
|
|||
*/
|
||||
function woocommerce_recount_after_stock_change( $product_id ) {
|
||||
|
||||
$product_cats = $product_tags = array();
|
||||
|
||||
$product_terms = get_the_terms( $product_id, 'product_cat' );
|
||||
foreach ( $product_terms as $term )
|
||||
$product_cats[ $term->term_id ] = $term->parent;
|
||||
|
||||
if ( $product_terms ) {
|
||||
foreach ( $product_terms as $term )
|
||||
$product_cats[ $term->term_id ] = $term->parent;
|
||||
|
||||
_woocommerce_term_recount( $product_cats, get_taxonomy( 'product_cat' ), false, false );
|
||||
|
||||
}
|
||||
|
||||
$product_terms = get_the_terms( $product_id, 'product_tag' );
|
||||
foreach ( $product_terms as $term )
|
||||
$product_tags[ $term->term_id ] = $term->parent;
|
||||
|
||||
_woocommerce_term_recount( $product_cats, get_taxonomy( 'product_cat' ), false, false );
|
||||
_woocommerce_term_recount( $product_tags, get_taxonomy( 'product_tag' ), false, false );
|
||||
if ( $product_terms ) {
|
||||
foreach ( $product_terms as $term )
|
||||
$product_tags[ $term->term_id ] = $term->parent;
|
||||
|
||||
_woocommerce_term_recount( $product_tags, get_taxonomy( 'product_tag' ), false, false );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
add_action( 'woocommerce_product_set_stock_status', 'woocommerce_recount_after_stock_change' );
|
||||
|
|
Loading…
Reference in New Issue