From 3f247b2c18b1c09d8d85742646d9e890c01cfeae Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 3 Nov 2011 11:48:59 +0000 Subject: [PATCH] Not the nicest way to do nested categories, but better than rewriting the walkers --- admin/admin-post-types.php | 62 +++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/admin/admin-post-types.php b/admin/admin-post-types.php index 672ea027e33..e7de4e8ba0f 100644 --- a/admin/admin-post-types.php +++ b/admin/admin-post-types.php @@ -294,28 +294,82 @@ function woocommerce_custom_product_orderby( $vars ) { } /** - * Filter products by category + * Filter products by category, uses slugs for option values. Code adapted by Andrew Benbow - chromeorange.co.uk **/ add_action('restrict_manage_posts','woocommerce_products_by_category'); function woocommerce_products_by_category() { global $typenow, $wp_query; if ($typenow=='product') : - $terms = get_terms('product_cat', 'pad_counts=1&hierarchal=1'); + $terms = get_terms('product_cat', 'pad_counts=1&hierarchal=1&hide_empty=1&child_of=0'); $output = ""; echo $output; endif; } +function woocommerce_get_product_category_depth( $id = '', $depth = '', $i = '' ) { + global $wpdb, $term_taxonomy; + + if( $depth == '' ) : + + if( $id == '' ) $id = $term_taxonomy->term_id; + + $depth = $wpdb->get_var($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = '%s'", $id)); + return woocommerce_get_product_category_depth($id, $depth, $i); + + elseif( $depth == "0" ) : + + return $i; + + else : + + $depth = $wpdb->get_var($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = '%s'", $depth)); + $i .='   '; + return woocommerce_get_product_category_depth($id, $depth, $i); + + endif; +} + +function woocommerce_get_product_category_children( $id = '' ) { + global $wp_query; + + if (!$id) return; + + $output = ''; + + $terms = get_terms('product_cat', 'pad_counts=1&hierarchal=1&hide_empty=1&child_of='.esc_attr($id)); + + foreach( $terms as $term ) : + if ($term->parent!=$id) continue; + + $depth = woocommerce_get_product_category_depth($term->term_id); + + if ( isset( $wp_query->query['product_cat'] ) ) : + $output .=""; + else : + $output .=""; + endif; + $output .= woocommerce_get_product_category_children($term->term_id); + + endforeach; + + return $output; +} + /** * Filter products by type