reports for subcats. Closes #1924.

This commit is contained in:
Mike Jolley 2012-12-05 18:36:30 +00:00
parent 5a7bfe980a
commit 86adc50964
2 changed files with 16 additions and 11 deletions

View File

@ -1918,7 +1918,7 @@ function woocommerce_category_sales() {
$current_year = isset( $_POST['show_year'] ) ? $_POST['show_year'] : date( 'Y', current_time( 'timestamp' ) );
$start_date = strtotime( $current_year . '0101' );
$categories = get_terms( 'product_cat', array( 'parent' => 0 ) );
$categories = get_terms( 'product_cat', array( 'orderby' => 'name' ) );
?>
<form method="post" action="" class="report_filters">
<p>
@ -1932,14 +1932,16 @@ function woocommerce_category_sales() {
<select multiple="multiple" class="chosen_select" id="show_categories" name="show_categories[]" style="width: 300px;">
<?php
foreach ( $categories as $category ) {
if ( $category->parent > 0 )
$prepend = '&mdash; ';
else
$prepend = '';
$r = array();
$r['pad_counts'] = 1;
$r['hierarchal'] = 1;
$r['hide_empty'] = 1;
$r['value'] = 'id';
$r['selected'] = isset( $_POST['show_categories'] ) ? $_POST['show_categories'] : '';
echo '<option value="' . $category->term_id . '" ' . selected( ! empty( $_POST['show_categories'] ) && in_array( $category->term_id, $_POST['show_categories'] ), true ) . '>' . $prepend . $category->name . '</option>';
}
include_once( $woocommerce->plugin_path() . '/classes/walkers/class-product-cat-dropdown-walker.php' );
echo woocommerce_walk_category_dropdown_tree( $categories, 0, $r );
?>
</select>

View File

@ -29,16 +29,19 @@ class WC_Product_Cat_Dropdown_Walker extends Walker {
$pad = str_repeat('&nbsp;', $depth * 3);
$cat_name = apply_filters( 'list_product_cats', $cat->name, $cat );
$output .= "\t<option class=\"level-$depth\" value=\"" . $cat->slug . "\"";
if ( $cat->slug == $args['selected'] )
$value = isset( $args['value'] ) && $args['value'] == 'id' ? $cat->term_id : $cat->slug;
$output .= "\t<option class=\"level-$depth\" value=\"" . $value . "\"";
if ( $value == $args['selected'] || ( is_array( $args['selected'] ) && in_array( $value, $args['selected'] ) ) )
$output .= ' selected="selected"';
$output .= '>';
$output .= $pad . __( $cat_name, 'woocommerce' );
if ( $args['show_count'] )
if ( ! empty( $args['show_count'] ) )
$output .= '&nbsp;(' . $cat->count . ')';
$output .= "</option>\n";