Automattic\WooCommerce\Blocks\BlockTypes

ProductCategories::renderDropdown()protectedWC 1.0

Render the category list as a dropdown.

Method of the class: ProductCategories{}

No Hooks.

Return

String. Rendered output.

Usage

// protected - for code of main (parent) or child class
$result = $this->renderDropdown( $categories, $attributes, $uid );
$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.

ProductCategories::renderDropdown() code WC 8.7.0

protected function renderDropdown( $categories, $attributes, $uid ) {
	$aria_label = empty( $attributes['hasCount'] ) ?
		__( 'List of categories', 'woocommerce' ) :
		__( 'List of categories with their product counts', 'woocommerce' );

	$output = '
		<div class="wc-block-product-categories__dropdown">
			<label
			class="screen-reader-text"
				for="' . esc_attr( $uid ) . '-select"
			>
				' . esc_html__( 'Select a category', 'woocommerce' ) . '
			</label>
			<select aria-label="' . esc_attr( $aria_label ) . '" id="' . esc_attr( $uid ) . '-select">
				<option value="false" hidden>
					' . esc_html__( 'Select a category', 'woocommerce' ) . '
				</option>
				' . $this->renderDropdownOptions( $categories, $attributes, $uid ) . '
			</select>
		</div>
		<button
			type="button"
			class="wc-block-product-categories__button"
			aria-label="' . esc_html__( 'Go to category', 'woocommerce' ) . '"
			onclick="const url = document.getElementById( \'' . esc_attr( $uid ) . '-select\' ).value; if ( \'false\' !== url ) document.location.href = url;"
		>
			<svg
				aria-hidden="true"
				role="img"
				focusable="false"
				class="dashicon dashicons-arrow-right-alt2"
				xmlns="http://www.w3.org/2000/svg"
				width="20"
				height="20"
				viewBox="0 0 20 20"
			>
				<path d="M6 15l5-5-5-5 1-2 7 7-7 7z" />
			</svg>
		</button>
	';
	return $output;
}