WC_Product_Cat_Dropdown_Walker::start_el( string $output, object $cat, int $depth, array $args = array(), int $current_object_id )

Starts the list before the elements are added.


Description Description

See also See also


Top ↑

Parameters Parameters

$output

(Required) Passed by reference. Used to append additional content.

$cat

(Required) Category.

$depth

(Required) Depth of category in reference to parents.

$args

(Optional) Arguments.

Default value: array()

$current_object_id

(Required) Current object ID.


Top ↑

Source Source

File: includes/walkers/class-wc-product-cat-dropdown-walker.php

	public function start_el( &$output, $cat, $depth = 0, $args = array(), $current_object_id = 0 ) {

		if ( ! empty( $args['hierarchical'] ) ) {
			$pad = str_repeat( ' ', $depth * 3 );
		} else {
			$pad = '';
		}

		$cat_name = apply_filters( 'list_product_cats', $cat->name, $cat );
		$value    = ( isset( $args['value'] ) && 'id' === $args['value'] ) ? $cat->term_id : $cat->slug;
		$output  .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $value ) . '"';

		if ( $value === $args['selected'] || ( is_array( $args['selected'] ) && in_array( $value, $args['selected'], true ) ) ) {
			$output .= ' selected="selected"';
		}

		$output .= '>';
		$output .= esc_html( $pad . $cat_name );

		if ( ! empty( $args['show_count'] ) ) {
			$output .= '&nbsp;(' . absint( $cat->count ) . ')';
		}

		$output .= "</option>\n";
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.