WC_Widget_Layered_Nav::widget()publicWC 1.0

Output widget.

Method of the class: WC_Widget_Layered_Nav{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Widget_Layered_Nav = new WC_Widget_Layered_Nav();
$WC_Widget_Layered_Nav->widget( $args, $instance );
$args(array) (required)
Arguments.
$instance(array) (required)
Instance.

Notes

WC_Widget_Layered_Nav::widget() code WC 9.4.2

public function widget( $args, $instance ) {
	if ( ! is_shop() && ! is_product_taxonomy() ) {
		return;
	}

	$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
	$taxonomy           = $this->get_instance_taxonomy( $instance );
	$query_type         = $this->get_instance_query_type( $instance );
	$display_type       = $this->get_instance_display_type( $instance );

	if ( ! taxonomy_exists( $taxonomy ) ) {
		return;
	}

	$terms = get_terms( $taxonomy, array( 'hide_empty' => '1' ) );

	if ( 0 === count( $terms ) ) {
		return;
	}

	ob_start();

	$this->widget_start( $args, $instance );

	if ( 'dropdown' === $display_type ) {
		wp_enqueue_script( 'selectWoo' );
		wp_enqueue_style( 'select2' );
		$found = $this->layered_nav_dropdown( $terms, $taxonomy, $query_type );
	} else {
		$found = $this->layered_nav_list( $terms, $taxonomy, $query_type );
	}

	$this->widget_end( $args );

	// Force found when option is selected - do not force found on taxonomy attributes.
	if ( ! is_tax() && is_array( $_chosen_attributes ) && array_key_exists( $taxonomy, $_chosen_attributes ) ) {
		$found = true;
	}

	if ( ! $found ) {
		ob_end_clean();
	} else {
		echo ob_get_clean(); // @codingStandardsIgnoreLine
	}
}