WC_Product_Cat_List_Walker

The WooCommerce WC Product Cat List Walker class.

Defined (1)

The class is defined in the following location(s).

/includes/walkers/class-product-cat-list-walker.php  
  1. class WC_Product_Cat_List_Walker extends Walker { 
  2.  
  3. /** 
  4. * What the class handles. 
  5. * @var string 
  6. */ 
  7. public $tree_type = 'product_cat'; 
  8.  
  9. /** 
  10. * DB fields to use. 
  11. * @var array 
  12. */ 
  13. public $db_fields = array( 
  14. 'parent' => 'parent',  
  15. 'id' => 'term_id',  
  16. 'slug' => 'slug',  
  17. ); 
  18.  
  19. /** 
  20. * Starts the list before the elements are added. 
  21. * @see Walker::start_lvl() 
  22. * @since 2.1.0 
  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. * Ends the list of after the elements are added. 
  36. * @see Walker::end_lvl() 
  37. * @since 2.1.0 
  38. * @param string $output Passed by reference. Used to append additional content. 
  39. * @param int $depth Depth of category. Used for tab indentation. 
  40. * @param array $args Will only append content if style argument value is 'list'. 
  41. */ 
  42. public function end_lvl( &$output, $depth = 0, $args = array() ) { 
  43. if ( 'list' != $args['style'] ) 
  44. return; 
  45.  
  46. $indent = str_repeat( "\t", $depth ); 
  47. $output .= "$indent</ul>\n"; 
  48.  
  49. /** 
  50. * Start the element output. 
  51. * @see Walker::start_el() 
  52. * @since 2.1.0 
  53. * @param string $output Passed by reference. Used to append additional content. 
  54. * @param int $depth Depth of category in reference to parents. 
  55. * @param integer $current_object_id 
  56. */ 
  57. public function start_el( &$output, $cat, $depth = 0, $args = array(), $current_object_id = 0 ) { 
  58. $output .= '<li class="cat-item cat-item-' . $cat->term_id; 
  59.  
  60. if ( $args['current_category'] == $cat->term_id ) { 
  61. $output .= ' current-cat'; 
  62.  
  63. if ( $args['has_children'] && $args['hierarchical'] ) { 
  64. $output .= ' cat-parent'; 
  65.  
  66. if ( $args['current_category_ancestors'] && $args['current_category'] && in_array( $cat->term_id, $args['current_category_ancestors'] ) ) { 
  67. $output .= ' current-cat-parent'; 
  68.  
  69. $output .= '"><a href="' . get_term_link( (int) $cat->term_id, $this->tree_type ) . '">' . _x( $cat->name, 'product category name', 'woocommerce' ) . '</a>'; 
  70.  
  71. if ( $args['show_count'] ) { 
  72. $output .= ' <span class="count">(' . $cat->count . ')</span>'; 
  73.  
  74. /** 
  75. * Ends the element output, if needed. 
  76. * @see Walker::end_el() 
  77. * @since 2.1.0 
  78. * @param string $output Passed by reference. Used to append additional content. 
  79. * @param int $depth Depth of category. Not used. 
  80. * @param array $args Only uses 'list' for whether should append to output. 
  81. */ 
  82. public function end_el( &$output, $cat, $depth = 0, $args = array() ) { 
  83. $output .= "</li>\n"; 
  84.  
  85. /** 
  86. * Traverse elements to create list from elements. 
  87. * Display one element if the element doesn't have any children otherwise,  
  88. * display the element and its children. Will only traverse up to the max. 
  89. * depth and no ignore elements under that depth. It is possible to set the. 
  90. * max depth to include all depths, see walk() method. 
  91. * This method shouldn't be called directly, use the walk() method instead. 
  92. * @since 2.5.0 
  93. * @param object $element Data object 
  94. * @param array $children_elements List of elements to continue traversing. 
  95. * @param int $max_depth Max depth to traverse. 
  96. * @param int $depth Depth of current element. 
  97. * @param array $args 
  98. * @param string $output Passed by reference. Used to append additional content. 
  99. * @return null Null on failure with no changes to parameters. 
  100. */ 
  101. public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { 
  102. if ( ! $element || ( 0 === $element->count && ! empty( $args[0]['hide_empty'] ) ) ) { 
  103. return; 
  104. parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );