1 <?php
 2 /**
 3  * WC_Product_Cat_Dropdown_Walker class.
 4  *
 5  * @extends     Walker
 6  * @class       WC_Product_Cat_Dropdown_Walker
 7  * @version     1.6.4
 8  * @package     WooCommerce/Classes/Walkers
 9  * @author      WooThemes
10  */
11 
12 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13 
14 class WC_Product_Cat_Dropdown_Walker extends Walker {
15 
16     var $tree_type = 'category';
17     var $db_fields = array ('parent' => 'parent', 'id' => 'term_id', 'slug' => 'slug' );
18 
19     /**
20      * @see Walker::start_el()
21      * @since 2.1.0
22      *
23      * @param string $output Passed by reference. Used to append additional content.
24      * @param object $category Category data object.
25      * @param int $depth Depth of category in reference to parents.
26      * @param integer $current_object_id
27      */
28     public function start_el( &$output, $cat, $depth = 0, $args = array(), $current_object_id = 0 ) {
29 
30         if ( ! empty( $args['hierarchical'] ) )
31             $pad = str_repeat('&nbsp;', $depth * 3);
32         else
33             $pad = '';
34 
35         $cat_name = apply_filters( 'list_product_cats', $cat->name, $cat );
36 
37         $value = isset( $args['value'] ) && $args['value'] == 'id' ? $cat->term_id : $cat->slug;
38 
39         $output .= "\t<option class=\"level-$depth\" value=\"" . $value . "\"";
40 
41         if ( $value == $args['selected'] || ( is_array( $args['selected'] ) && in_array( $value, $args['selected'] ) ) )
42             $output .= ' selected="selected"';
43 
44         $output .= '>';
45 
46         $output .= $pad . __( $cat_name, 'woocommerce' );
47 
48         if ( ! empty( $args['show_count'] ) )
49             $output .= '&nbsp;(' . $cat->count . ')';
50 
51         $output .= "</option>\n";
52     }
53 
54     /**
55      * Traverse elements to create list from elements.
56      *
57      * Display one element if the element doesn't have any children otherwise,
58      * display the element and its children. Will only traverse up to the max
59      * depth and no ignore elements under that depth. It is possible to set the
60      * max depth to include all depths, see walk() method.
61      *
62      * This method shouldn't be called directly, use the walk() method instead.
63      *
64      * @since 2.5.0
65      *
66      * @param object $element Data object
67      * @param array $children_elements List of elements to continue traversing.
68      * @param int $max_depth Max depth to traverse.
69      * @param int $depth Depth of current element.
70      * @param array $args
71      * @param string $output Passed by reference. Used to append additional content.
72      * @return null Null on failure with no changes to parameters.
73      */
74     public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
75         if ( ! $element || 0 === $element->count ) {
76             return;
77         }
78         parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
79     }   
80 }
WooCommerce API documentation generated by ApiGen 2.8.0