Suppose you want to show vendors of a “hoodies” category only.
Use this code in your currently active theme functions.php file.
/**** Add category attribute on vendor list shortcode *****/
add_filter('mvx_vendor_list_get_mvx_vendors_args', 'mvx_vendor_list_shortcode_category_attribute' , 10 , 4 );
function mvx_vendor_list_shortcode_category_attribute( $query, $order_by, $qst, $atts ){
if( empty( $atts ) ) return $query;
$block_vendors = wp_list_pluck(mvx_get_all_blocked_vendors(), 'id');
$include_vendors = array();
$pro_args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => array_map('sanitize_title', explode(',',$atts['category'])),
'field' => 'slug',
'operator' => 'IN'
)
)
);
$products = get_posts($pro_args);
$product_ids = wp_list_pluck($products, 'ID');
foreach ($product_ids as $product_id) {
$vendor = get_mvx_product_vendors($product_id);
if ($vendor && !in_array($vendor->id, $block_vendors)) {
$include_vendors[] = $vendor->id;
}
}
$query['include'] = $include_vendors;
return $query;
}
Then define the “category” attribute with vendor list shortcode :
[mvx_vendorslist orderby=”category” order=”ASC” category="hoodies"]
Leave a Reply
You must be logged in to post a comment.