Order Vendors List Widget Alphabetically
For some reason, if you use the WCMp Vendors List widget in a sidebar, the vendors are sorted by the date they joined. This makes it look super sloppy, so this snippet will simply sort the vendors in this widget alphabetically. Seems weird this needs to exist, but here you have it. This is set up to check per page, but personally I only have a sidebar on my homepage and just haven’t found it necessary to change it.
Also note: You don’t need a snippet to do this with your Vendors List page. Just use the shortcode options provided by WCMp. On my site, I use [wcmp_vendorslist orderby=”name” order=”ASC”].
As always, this is either added to your Child Theme’s functions.php file, or consider using the My Custom Functions Pro plugin to manage and organize all your snippets.
function modify_user_query( $query ) {
global $post;
if( is_home() || is_front_page() || is_woocommerce() ) {
$meta_query = $query->get('meta_query');
$meta_query[] = array(
'key'=>'_vendor_page_title',
);
$query->set('meta_query',$meta_query);
$query->set('orderby', 'meta_value');
$query->set('order', 'ASC');
}
}
add_action( 'pre_get_users', 'modify_user_query' );
Tested and working on Woocommerce 4.6.1, WCMp 3.5.10
Is this no longer relevant or not working? Please let us know in the comments!