WC_Product_Cat_Dropdown_Walker

The WooCommerce WC Product Cat Dropdown Walker class.

Defined (1)

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

/includes/walkers/class-product-cat-dropdown-walker.php  
  1. class WC_Product_Cat_Dropdown_Walker extends Walker { 
  2.  
  3. /** 
  4. * What the class handles. 
  5. * @var string 
  6. */ 
  7. public $tree_type = 'category'; 
  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_el() 
  22. * @since 2.1.0 
  23. * @param string $output Passed by reference. Used to append additional content. 
  24. * @param int $depth Depth of category in reference to parents. 
  25. * @param integer $current_object_id 
  26. */ 
  27. public function start_el( &$output, $cat, $depth = 0, $args = array(), $current_object_id = 0 ) { 
  28.  
  29. if ( ! empty( $args['hierarchical'] ) ) { 
  30. $pad = str_repeat( ' ', $depth * 3 ); 
  31. } else { 
  32. $pad = ''; 
  33.  
  34. $cat_name = apply_filters( 'list_product_cats', $cat->name, $cat ); 
  35. $value = ( isset( $args['value'] ) && 'id' === $args['value'] ) ? $cat->term_id : $cat->slug; 
  36. $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $value ) . "\""; 
  37.  
  38. if ( $value === $args['selected'] || ( is_array( $args['selected'] ) && in_array( $value, $args['selected'] ) ) ) { 
  39. $output .= ' selected="selected"'; 
  40.  
  41. $output .= '>'; 
  42. $output .= esc_html( $pad . _x( $cat_name, 'product category name', 'woocommerce' ) ); 
  43.  
  44. if ( ! empty( $args['show_count'] ) ) { 
  45. $output .= ' (' . absint( $cat->count ) . ')'; 
  46.  
  47. $output .= "</option>\n"; 
  48.  
  49. /** 
  50. * Traverse elements to create list from elements. 
  51. * Display one element if the element doesn't have any children otherwise,  
  52. * display the element and its children. Will only traverse up to the max. 
  53. * depth and no ignore elements under that depth. It is possible to set the. 
  54. * max depth to include all depths, see walk() method. 
  55. * This method shouldn't be called directly, use the walk() method instead. 
  56. * @since 2.5.0 
  57. * @param object $element Data object 
  58. * @param array $children_elements List of elements to continue traversing. 
  59. * @param int $max_depth Max depth to traverse. 
  60. * @param int $depth Depth of current element. 
  61. * @param array $args 
  62. * @param string $output Passed by reference. Used to append additional content. 
  63. * @return null Null on failure with no changes to parameters. 
  64. */ 
  65. public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { 
  66. if ( ! $element || ( 0 === $element->count && ! empty( $args[0]['hide_empty'] ) ) ) { 
  67. return; 
  68. parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );