Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterAttribute::render_attribute_checkbox_list()privateWC 1.0

Render the attribute filter checkbox list.

Method of the class: ProductFilterAttribute{}

No Hooks.

Return

String.

Usage

// private - for code of main (parent) class only
$result = $this->render_attribute_checkbox_list( $options, $attributes );
$options(mixed) (required)
Attribute filter options to render in the checkbox list.
$attributes(mixed) (required)
Block attributes.

ProductFilterAttribute::render_attribute_checkbox_list() code WC 8.9.0

private function render_attribute_checkbox_list( $options, $attributes ) {
	if ( empty( $options ) ) {
		return '';
	}

	$show_counts = $attributes['showCounts'] ?? false;

	$list_options = array_map(
		function( $option ) use ( $show_counts ) {
			return array(
				'id'      => $option['slug'] . '-' . $option['term_id'],
				'checked' => $option['selected'],
				'label'   => $show_counts ? sprintf( '%1$s (%2$d)', $option['name'], $option['count'] ) : $option['name'],
				'value'   => $option['slug'],
			);
		},
		$options
	);

	return CheckboxList::render(
		array(
			'items'     => $list_options,
			'on_change' => "{$this->get_full_block_name()}::actions.updateProducts",
		)
	);
}