Last active
October 18, 2016 22:58
-
-
Save digitalchild/5ff5bf34571a4adef995 to your computer and use it in GitHub Desktop.
Add a WC Vendors Tab to the Buddy Press profile
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 | |
// This snippet will add an extra tab to the buddy press user profile that can call any shortcode defined in WC Vendors. | |
// This code should be inserted into your bp-custom.php file. | |
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 Store', 'buddypress' ), | |
'slug' => 'my-store', | |
'position' => 99, | |
'screen_function' => 'wcv_store_display', | |
'default_subnav_slug' => 'my-store', | |
'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