Created
May 29, 2015 07:23
-
-
Save digitalchild/84ec20a1721253b7215b to your computer and use it in GitHub Desktop.
Hijack primary menu to add link to vendors store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Only run if wcv_vendors is installed. | |
* | |
* Place this in your themes functions.php file. | |
*/ | |
if ( class_exists( 'WCV_Vendors' ) ) { | |
/** | |
* Hijack the PRIMARY menu and add a 'View my store' to the menu. | |
* | |
* Change primary to whatever your menu location is that you want to hijack. | |
*/ | |
function wcv_vendor_store_link( $items, $args ) { | |
if (WCV_Vendors::is_vendor( get_current_user_id() ) ) { | |
$wcv_shop_permalink = WC_Vendors::$pv_options->get_option( 'vendor_shop_permalink' ); | |
if( is_user_logged_in() && ( $args->theme_location == 'primary' ) ) { | |
$vendor = get_userdata( get_current_user_id() ); | |
$store_url = '<li><a title="View My Closet" href="'. esc_url( site_url( $wcv_shop_permalink . $vendor->pv_shop_slug ) ) .'">View My Store</a></li>'; | |
$newitems = $items. $store_url;// enqueue regular menu item | |
return $newitems; | |
} | |
} | |
return $items; | |
} | |
add_filter('wp_nav_menu_items', 'wcv_vendor_store_link', 10, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment