Automattic\WooCommerce\Blocks\BlockTypes
ProductCategories::renderDropdownOptions()
Render dropdown options list.
Method of the class: ProductCategories{}
No Hooks.
Return
String
. Rendered output.
Usage
// protected - for code of main (parent) or child class $result = $this->renderDropdownOptions( $categories, $attributes, $uid, $depth );
- $categories(array) (required)
- List of terms.
- $attributes(array) (required)
- Block attributes.
Default: empty array - $uid(int) (required)
- Unique ID for the rendered block, used for HTML IDs.
- $depth(int)
- Current depth.
ProductCategories::renderDropdownOptions() ProductCategories::renderDropdownOptions code WC 9.4.2
protected function renderDropdownOptions( $categories, $attributes, $uid, $depth = 0 ) { $output = ''; foreach ( $categories as $category ) { $output .= ' <option value="' . esc_attr( get_term_link( $category->term_id, 'product_cat' ) ) . '"> ' . str_repeat( '−', $depth ) . ' ' . esc_html( $category->name ) . ' ' . $this->getCount( $category, $attributes ) . ' </option> ' . ( ! empty( $category->children ) ? $this->renderDropdownOptions( $category->children, $attributes, $uid, $depth + 1 ) : '' ) . ' '; } return $output; }