Merge pull request #2008 from warrendholmes/master

- Make sure product has categories/tags when updating stock status.
This commit is contained in:
Coen Jacobs 2012-12-17 12:51:20 -08:00
commit 2630b2f4a8
1 changed files with 16 additions and 8 deletions

View File

@ -2008,18 +2008,26 @@ function _woocommerce_term_recount( $terms, $taxonomy, $callback = true, $terms_
*/ */
function woocommerce_recount_after_stock_change( $product_id ) { function woocommerce_recount_after_stock_change( $product_id ) {
$product_cats = $product_tags = array();
$product_terms = get_the_terms( $product_id, 'product_cat' ); $product_terms = get_the_terms( $product_id, 'product_cat' );
if ( $product_terms ) {
foreach ( $product_terms as $term ) foreach ( $product_terms as $term )
$product_cats[ $term->term_id ] = $term->parent; $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' ); $product_terms = get_the_terms( $product_id, 'product_tag' );
if ( $product_terms ) {
foreach ( $product_terms as $term ) foreach ( $product_terms as $term )
$product_tags[ $term->term_id ] = $term->parent; $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 ); _woocommerce_term_recount( $product_tags, get_taxonomy( 'product_tag' ), false, false );
}
} }
add_action( 'woocommerce_product_set_stock_status', 'woocommerce_recount_after_stock_change' ); add_action( 'woocommerce_product_set_stock_status', 'woocommerce_recount_after_stock_change' );