1 <?php
2 /**
3 * WC_Product_Cat_List_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_List_Walker extends Walker {
15
16 var $tree_type = 'product_cat';
17 var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id', 'slug' => 'slug' );
18
19 /**
20 * @see Walker::start_lvl()
21 * @since 2.1.0
22 *
23 * @param string $output Passed by reference. Used to append additional content.
24 * @param int $depth Depth of category. Used for tab indentation.
25 * @param array $args Will only append content if style argument value is 'list'.
26 */
27 public function start_lvl( &$output, $depth = 0, $args = array() ) {
28 if ( 'list' != $args['style'] )
29 return;
30
31 $indent = str_repeat("\t", $depth);
32 $output .= "$indent<ul class='children'>\n";
33 }
34
35 /**
36 * @see Walker::end_lvl()
37 * @since 2.1.0
38 *
39 * @param string $output Passed by reference. Used to append additional content.
40 * @param int $depth Depth of category. Used for tab indentation.
41 * @param array $args Will only append content if style argument value is 'list'.
42 */
43 public function end_lvl( &$output, $depth = 0, $args = array() ) {
44 if ( 'list' != $args['style'] )
45 return;
46
47 $indent = str_repeat("\t", $depth);
48 $output .= "$indent</ul>\n";
49 }
50
51 /**
52 * @see Walker::start_el()
53 * @since 2.1.0
54 *
55 * @param string $output Passed by reference. Used to append additional content.
56 * @param object $category Category data object.
57 * @param int $depth Depth of category in reference to parents.
58 * @param integer $current_object_id
59 */
60 public function start_el( &$output, $cat, $depth = 0, $args = array(), $current_object_id = 0 ) {
61 $output .= '<li class="cat-item cat-item-' . $cat->term_id;
62
63 if ( $args['current_category'] == $cat->term_id ) {
64 $output .= ' current-cat';
65 }
66
67 if ( $args['has_children'] && $args['hierarchical'] ) {
68 $output .= ' cat-parent';
69 }
70
71 if ( $args['current_category_ancestors'] && $args['current_category'] && in_array( $cat->term_id, $args['current_category_ancestors'] ) ) {
72 $output .= ' current-cat-parent';
73 }
74
75 $output .= '"><a href="' . get_term_link( (int) $cat->term_id, 'product_cat' ) . '">' . __( $cat->name, 'woocommerce' ) . '</a>';
76
77 if ( $args['show_count'] ) {
78 $output .= ' <span class="count">(' . $cat->count . ')</span>';
79 }
80 }
81
82 /**
83 * @see Walker::end_el()
84 * @since 2.1.0
85 *
86 * @param string $output Passed by reference. Used to append additional content.
87 * @param object $page Not used.
88 * @param int $depth Depth of category. Not used.
89 * @param array $args Only uses 'list' for whether should append to output.
90 */
91 public function end_el( &$output, $cat, $depth = 0, $args = array() ) {
92 $output .= "</li>\n";
93 }
94
95 /**
96 * Traverse elements to create list from elements.
97 *
98 * Display one element if the element doesn't have any children otherwise,
99 * display the element and its children. Will only traverse up to the max
100 * depth and no ignore elements under that depth. It is possible to set the
101 * max depth to include all depths, see walk() method.
102 *
103 * This method shouldn't be called directly, use the walk() method instead.
104 *
105 * @since 2.5.0
106 *
107 * @param object $element Data object
108 * @param array $children_elements List of elements to continue traversing.
109 * @param int $max_depth Max depth to traverse.
110 * @param int $depth Depth of current element.
111 * @param array $args
112 * @param string $output Passed by reference. Used to append additional content.
113 * @return null Null on failure with no changes to parameters.
114 */
115 public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
116 if ( ! $element || 0 === $element->count ) {
117 return;
118 }
119 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
120 }
121 }