Created
July 9, 2017 03:58
-
-
Save fervous/94fce317b4661885cc04722524912933 to your computer and use it in GitHub Desktop.
wc vendors show vendor's products in new my products tab in buddypress bp
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
//BP MY PRODUCTS | |
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_nicename.'"]'); | |
} | |
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