@chiragagarwal, to do so first of all you have to create a custom widget for it, because our above widget is restricted to vendor shop page only. To create a custom widget, please follows this link.
After successfully created your widget, just replace your class widget’s widget()
function with follows-
public function widget( $args, $instance ) {
$query_args = array(
'posts_per_page' => -1,
'no_found_rows' => 1,
'author__in' => array( 2 ),
'post_status' => 'publish',
'post_type' => 'product',
'meta_key' => '_wc_average_rating',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => WC()->query->get_meta_query(),
'tax_query' => WC()->query->get_tax_query(),
); // WPCS: slow query ok.
$r = new WP_Query( $query_args );
if ( $r->have_posts() ) {
echo "My Widget Title"; // Title displayed on sidebar
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
$template_args = array(
'widget_id' => $args['widget_id'],
'show_rating' => true,
);
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>' ) );
}
wp_reset_postdata();
$content = ob_get_clean();
echo $content; // WPCS: XSS ok.
}
Where author__in
array contain vendor ID (Ex. 2), you can replace it with multiple.