1. Home
  2. WC Vendors Marketplace
  3. Code Snippets
  4. Dynamically Created Vendor Menus

Dynamically Created Vendor Menus

This code will add a list of all vendors, as a menu item, on your site. Have fun, and tweak it any way you see fit.

This code should be placed in your themes functions.php file.

add_filter( 'wp_nav_menu_items', 'wcv_vendors_menu', 10, 2 );
function wcv_vendors_menu ( $items, $args ) {
   	if ($args->theme_location == 'primary') {
		$vendors  = get_users( array( 'role' => 'vendor' ) ); 
		$items .= '<li><a href="#">Vendors</a>'; 
		$items .= '<ul class="sub-menu">'; 
		foreach( $vendors as $vendor ) { 
			$vendor_shop_link = site_url( WC_Vendors::$pv_options->get_option( 'vendor_shop_permalink' ) .$vendor->pv_shop_slug ); 
			$items .= '<li><a href="'.$vendor_shop_link.'">'.$vendor->pv_shop_name.'</a></li>';
		}
		$items .= '</ul></li>'; 
   	}
    return $items;
}

 

filters

Updated on October 17, 2016

Was this article helpful?