WC_Widget_Recently_Viewed::widget()
Output widget.
Method of the class: WC_Widget_Recently_Viewed{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Widget_Recently_Viewed = new WC_Widget_Recently_Viewed(); $WC_Widget_Recently_Viewed->widget( $args, $instance );
- $args(array) (required)
- Arguments.
- $instance(array) (required)
- Widget instance.
Notes
- See: WP_Widget
WC_Widget_Recently_Viewed::widget() WC Widget Recently Viewed::widget code WC 9.4.2
public function widget( $args, $instance ) { $viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', wp_unslash( $_COOKIE['woocommerce_recently_viewed'] ) ) : array(); // @codingStandardsIgnoreLine $viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) ); if ( empty( $viewed_products ) ) { return; } ob_start(); $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; $query_args = array( 'posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $viewed_products, 'orderby' => 'post__in', ); if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { $query_args['tax_query'] = array( array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'outofstock', 'operator' => 'NOT IN', ), ); // WPCS: slow query ok. } $r = new WP_Query( apply_filters( 'woocommerce_recently_viewed_products_widget_query_args', $query_args ) ); if ( $r->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, ); while ( $r->have_posts() ) { $r->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(); $content = ob_get_clean(); echo $content; // WPCS: XSS ok. }