Automattic\WooCommerce\Blocks\BlockTypes

ProductCategories::renderDropdown()protectedWC 1.0

Render the category list as a dropdown.

Метод класса: ProductCategories{}

Хуков нет.

Возвращает

Строку. Rendered output.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->renderDropdown( $categories, $attributes, $uid );
$categories(массив) (обязательный)
List of terms.
$attributes(массив) (обязательный)
Block attributes.
По умолчанию: empty array
$uid(int) (обязательный)
Unique ID for the rendered block, used for HTML IDs.

Код ProductCategories::renderDropdown() WC 9.3.3

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;
}