WC_Widget_Products::widget()publicWC 1.0

Output widget.

Method of the class: WC_Widget_Products{}

Return

null. Nothing (null).

Usage

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

Notes

WC_Widget_Products::widget() code WC 8.6.1

public function widget( $args, $instance ) {
	if ( $this->get_cached_widget( $args ) ) {
		return;
	}

	ob_start();

	wc_set_loop_prop( 'name', 'widget' );

	$products = $this->get_products( $args, $instance );
	if ( $products && $products->have_posts() ) {
		$this->widget_start( $args, $instance );

		echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );

		$template_args = array(
			'widget_id'   => isset( $args['widget_id'] ) ? $args['widget_id'] : $this->widget_id,
			'show_rating' => true,
		);

		while ( $products->have_posts() ) {
			$products->the_post();
			wc_get_template( 'content-widget-product.php', $template_args );
		}

		echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_list', '</ul>' ) );

		$this->widget_end( $args );
	}

	wp_reset_postdata();

	echo $this->cache_widget( $args, ob_get_clean() ); // WPCS: XSS ok.
}