Skip to content

Instantly share code, notes, and snippets.

@kriot1
Last active August 29, 2015 14:21
Show Gist options
  • Save kriot1/c202829b06acc2e92e68 to your computer and use it in GitHub Desktop.
Save kriot1/c202829b06acc2e92e68 to your computer and use it in GitHub Desktop.
// Add the WooComm Account sub-navigation menu item to BuddyPress' Profile navigation array
add_action( 'bp_setup_nav', 'my_woo_info_nav' );
function my_woo_info_nav() {
global $bp;
$profile_link = trailingslashit( $bp->loggedin_user->domain . $bp->profile->slug );
bp_core_new_subnav_item( array( 'name' => __( 'Account', 'buddypress' ), 'slug' => 'account', 'parent_url' => $profile_link, 'parent_slug' => $bp->profile->slug, 'screen_function' => 'bp_woo_profile_subscription_screen', 'position' => 30, 'item_css_id' => 'accounthip' ) );
}
// This is the screen_function used by BuddyPress' navigation
function bp_woo_profile_subscription_screen() {
add_action( 'bp_template_title', 'bp_woo_profile_subscription_screen_title' );
add_action( 'bp_template_content', 'bp_woo_profile_subscription_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
// Echo the screen title
function bp_woo_profile_subscription_screen_title() {
echo 'Account Settings';
}
// Add the WooCommerce My Account shortcode to the screen
function bp_woo_profile_subscription_screen_content() {
echo do_shortcode( '[woocommerce_my_account]' );
}
// When an address is updated, redirect paying account back to BuddyPress profile
add_action( 'woocommerce_customer_save_address', 'save_address_locate_to_bp_profile' );
function save_address_locate_to_bp_profile() {
global $bp;
if( current_user_can( 'account' ) ) {
wp_safe_redirect( $bp->loggedin_user->domain . $bp->profile->slug . '/accounthip/' );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment