Created
May 16, 2016 00:46
-
-
Save bentasm1/350b6e50351fde5645b3451c02812f6d to your computer and use it in GitHub Desktop.
WC Vendors - Show vendors products in BuddyPress
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
/* Code by Fervous | |
* WC Vendors - Shows a "My Products" tab in BuddyPress and then the vendors products in that tab | |
*/ | |
function my_bp_nav_adder() { | |
if (class_exists('WC_Vendors')) { | |
$wcv_profile_id = bp_displayed_user_id(); | |
$wcv_profile_info = get_userdata( bp_displayed_user_id() ); | |
if ( $wcv_profile_info->roles[0] == "vendor" ) { | |
global $bp; | |
bp_core_new_nav_item( | |
array( | |
'name' => __( 'My Products', 'buddypress' ), | |
'slug' => 'my-products', | |
'position' => 30, | |
'screen_function' => 'wcv_store_display', | |
'default_subnav_slug' => 'my-products', | |
'parent_url' => $bp->loggedin_user->domain . $bp->slug . '/', | |
'parent_slug' => $bp->slug | |
) ); | |
} | |
} | |
} | |
function wcv_store_display() { | |
//add title and content here - last is to call the members plugin.php template | |
add_action( 'bp_template_title', 'wcv_page_function_to_show_screen_title' ); | |
add_action( 'bp_template_content', 'wcv_page_function_to_show_screen_content' ); | |
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) ); | |
} | |
function wcv_page_function_to_show_screen_title() { | |
echo 'My Products'; | |
} | |
function wcv_page_function_to_show_screen_content() { | |
$wcv_user = get_userdata( bp_displayed_user_id() ); | |
// You can use any WCV_ shortcode available | |
echo do_shortcode('[wcv_products vendor="'.$wcv_user->user_login.'"]'); | |
} | |
add_action( 'bp_setup_nav', 'my_bp_nav_adder', 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment