From 0f9e9ed40e2ff93f9da906797ddccb246e4f797b Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Thu, 11 Oct 2012 11:46:53 +0200 Subject: [PATCH] Fixed notices possible with manual prod_cat counting --- woocommerce-core-functions.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/woocommerce-core-functions.php b/woocommerce-core-functions.php index bc3b7c71a51..12012d1c414 100644 --- a/woocommerce-core-functions.php +++ b/woocommerce-core-functions.php @@ -1662,12 +1662,16 @@ function woocommerce_manual_category_count( $terms, $taxonomy ) { $term = get_term( $term_id, 'product_cat' ); $counted_ids = get_option( 'wc_prod_cat_counts' ); - $counted_ids = ( ! is_array( $counted_ids ) ) ? array() : $counted_ids; + $counted_ids[ $term->term_id ] = ( isset( $counted_ids[ $term->term_id ] ) && ! is_array( $counted_ids[ $term->term_id ] ) ) ? array() : $counted_ids[ $term->term_id ]; if ( in_array( $_POST['_visibility'], $do_count ) ) { - if ( ! empty( $counted_ids[ $term->term_id ] ) && ! in_array( $_POST['post_ID'], $counted_ids[ $term->term_id ] ) ) { - $counted_ids[ $term->term_id ] = ( ! is_array( $counted_ids[ $term->term_id ] ) ) ? array() : $counted_ids[ $term->term_id ]; - array_push( $counted_ids[ $term->term_id ], absint( $_POST['post_ID'] ) ); + if ( ! empty( $counted_ids[ $term->term_id ] ) ) { + if ( ! in_array( $_POST['post_ID'], $counted_ids[ $term->term_id ] ) ) { + array_push( $counted_ids[ $term->term_id ], absint( $_POST['post_ID'] ) ); + update_option( 'wc_prod_cat_counts', $counted_ids ); + } + } else { + $counted_ids[ $term->term_id ] = array( absint( $_POST['post_ID'] ) ); update_option( 'wc_prod_cat_counts', $counted_ids ); } } elseif ( in_array( $_POST['_visibility'], $do_not_count ) ) {