Check categories and tags are available on a product before doing count updates.

This commit is contained in:
Warren Holmes 2012-12-17 14:39:27 +02:00
parent b5474d0a85
commit 98525111f3
1 changed files with 16 additions and 6 deletions

View File

@ -2011,15 +2011,25 @@ function woocommerce_recount_after_stock_change( $product_id ) {
$product_cats = $product_tags = array();
$product_terms = get_the_terms( $product_id, 'product_cat' );
if( count( $product_terms) ){
foreach ( $product_terms as $term )
$product_cats[ $term->term_id ] = $term->parent;
}
$product_terms = get_the_terms( $product_id, 'product_tag' );
if( count( $product_terms ) ){
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( count( $product_cats ) ) _woocommerce_term_recount( $product_cats, get_taxonomy( 'product_cat' ), false, false );
if( count( $product_cats ) ) _woocommerce_term_recount( $product_tags, get_taxonomy( 'product_tag' ), false, false );
}
add_action( 'woocommerce_product_set_stock_status', 'woocommerce_recount_after_stock_change' );