Reverted changes for manual category count. Ref: #1789
This commit is contained in:
parent
4720628a71
commit
22afc34052
|
@ -206,38 +206,4 @@ foreach ( $order_tax_rows as $order_tax_row ) {
|
|||
unset( $tax_amount );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update manual counters for product categories (only counting visible products, so visibility: 'visible' or 'catalog')
|
||||
// Loop through all products and put the IDs in array with each product category term id as index
|
||||
$products_query_args = array(
|
||||
'post_type' => 'product',
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => '_visibility',
|
||||
'value' => array( 'visible', 'catalog' ),
|
||||
'compare' => 'IN',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$products_query = new WP_Query( $products_query_args );
|
||||
|
||||
$counted_ids = array();
|
||||
|
||||
foreach( $products_query->posts as $visible_product ) {
|
||||
$product_terms = wp_get_post_terms( $visible_product->ID, 'product_cat', array( 'fields' => 'ids' ) );
|
||||
|
||||
foreach ( $product_terms as $product_term_id ) {
|
||||
if ( ! isset( $counted_ids[ $product_term_id ] ) || ! is_array( $counted_ids[ $product_term_id ] ) ) {
|
||||
$counted_ids[ $product_term_id ] = array();
|
||||
}
|
||||
|
||||
if ( ! in_array( $visible_product->ID, $counted_ids[ $product_term_id ] ) ) {
|
||||
array_push( $counted_ids[ $product_term_id ], $visible_product->ID );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'wc_prod_cat_counts', $counted_ids );
|
||||
}
|
|
@ -223,7 +223,6 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Fix - Added more error messages for coupons.
|
||||
* Fix - Variation sku updating after selection.
|
||||
* Fix - Active plugins display on status page.
|
||||
* Fix - Manual product category counting to make sure hidden products are not counted.
|
||||
|
||||
* Localization - French update by Arnaud Cheminand and absoluteweb.
|
||||
* Localization - Romanian update by silviu-bucsa.
|
||||
|
|
|
@ -1702,48 +1702,6 @@ function woocommerce_remove_roles() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual category counting to prevent category widget from showing hidden products in total
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function woocommerce_manual_category_count( $terms, $taxonomy ) {
|
||||
// Keep the normal count in sync
|
||||
_update_post_term_count( $terms, $taxonomy );
|
||||
|
||||
if ( isset( $_POST['post_ID'] ) && isset( $_POST['_visibility'] ) && 'product_cat' == $taxonomy->query_var ) {
|
||||
foreach ( $terms as $term_id ) {
|
||||
$do_count = array( 'visible', 'catalog' );
|
||||
$do_not_count = array( 'search', 'hidden' );
|
||||
|
||||
$counted_ids = get_option( 'wc_prod_cat_counts' );
|
||||
if ( ! is_array( $counted_ids ) )
|
||||
$counted_ids = array();
|
||||
$counted_ids[ $term_id ] = ( empty( $counted_ids[ $term_id ] ) || ! is_array( $counted_ids[ $term_id ] ) ) ? array() : $counted_ids[ $term_id ];
|
||||
|
||||
if ( in_array( $_POST['_visibility'], $do_count ) ) {
|
||||
if ( ! empty( $counted_ids[ $term_id ] ) ) {
|
||||
if ( ! in_array( $_POST['post_ID'], $counted_ids[ $term_id ] ) ) {
|
||||
array_push( $counted_ids[ $term_id ], absint( $_POST['post_ID'] ) );
|
||||
update_option( 'wc_prod_cat_counts', $counted_ids );
|
||||
}
|
||||
} else {
|
||||
$counted_ids[ $term_id ] = array( absint( $_POST['post_ID'] ) );
|
||||
update_option( 'wc_prod_cat_counts', $counted_ids );
|
||||
}
|
||||
} elseif ( in_array( $_POST['_visibility'], $do_not_count ) ) {
|
||||
if ( in_array( $_POST['post_ID'], $counted_ids[ $term_id ] ) ) {
|
||||
if ( ( $key = array_search( $_POST['post_ID'], $counted_ids[ $term_id ] ) ) !== false ) {
|
||||
unset( $counted_ids[ $term_id ][ $key ] );
|
||||
update_option( 'wc_prod_cat_counts', $counted_ids );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a item to an order (for example a line item).
|
||||
|
|
|
@ -1226,24 +1226,4 @@ function woocommerce_get_order_id_by_order_key( $order_key ) {
|
|||
$order_id = $wpdb->get_var( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '_order_key' AND meta_value = '{$order_key}'" );
|
||||
|
||||
return $order_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the count properties for all terms based on our manual counters
|
||||
*
|
||||
* @access public
|
||||
* @return array Contains all the terms with updated counts
|
||||
*/
|
||||
function wc_get_terms_count_filter( $terms, $taxonomies ) {
|
||||
if ( ! is_admin() && in_array( 'product_cat', $taxonomies ) ) {
|
||||
$counted_ids = get_option( 'wc_prod_cat_counts' );
|
||||
|
||||
foreach ( $terms as $term ) {
|
||||
if ( isset( $counted_ids[ $term->term_id ] ) ) {
|
||||
$term->count = count( $counted_ids[ $term->term_id ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $terms;
|
||||
}
|
|
@ -80,13 +80,6 @@ if ( ! is_admin() || defined('DOING_AJAX') ) {
|
|||
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
|
||||
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
|
||||
|
||||
/**
|
||||
* Categories
|
||||
*
|
||||
* @see wc_get_terms_count_filter()
|
||||
*/
|
||||
add_filter( 'get_terms', 'wc_get_terms_count_filter', 10, 2 );
|
||||
|
||||
/**
|
||||
* Subcategories
|
||||
*
|
||||
|
|
|
@ -666,7 +666,7 @@ class Woocommerce {
|
|||
array('product'),
|
||||
array(
|
||||
'hierarchical' => true,
|
||||
'update_count_callback' => 'woocommerce_manual_category_count',
|
||||
'update_count_callback' => '_update_post_term_count',
|
||||
'label' => __( 'Product Categories', 'woocommerce'),
|
||||
'labels' => array(
|
||||
'name' => __( 'Product Categories', 'woocommerce'),
|
||||
|
|
Loading…
Reference in New Issue