Skip to content

Instantly share code, notes, and snippets.

@digitalchild
Created February 25, 2015 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save digitalchild/db65c29a4ba3f0d6a31e to your computer and use it in GitHub Desktop.
Save digitalchild/db65c29a4ba3f0d6a31e to your computer and use it in GitHub Desktop.
WC Vendors Dynamic Menu
<?php
// Place this in your themes functions.php
// This will put the menu item in your primary menu. Change the theme location if you want to change which menu this goes in.
// Hook into the nav menu items
add_filter( 'wp_nav_menu_items', 'wcv_vendors_menu', 10, 2 );
// Generate the menu
function wcv_vendors_menu ( $items, $args ) {
if ($args->theme_location == 'primary') {
// Get all the vendors
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment