Display New Sidebar Nav on Woocommerce Account Page

I know, another sidebar thread.

Hopefully I can make this thread the official sidebar thread

I’m trying to create a sidebar navigation menu for the WooCommerce account page (or endpoint). This sidebar is just a static navigation that includes links to all of the account endpoints, creating a better UX. I want the sidebar floated left, its currently floated right by default.

Just for reference there’s a few resources already out there on the sidebar:

The official Roots docs sidebar article.
This github repo, focused on building a sidebar nav

Here’s what I think the workflow should look like:

  1. Register a new sidebar in lib/widgets.php

  2. Register a new menu in lib/init.php

  3. Setup menu links in WP menu admin.

  4. Update your sidebar in the WP widgets admin panel, make it your menu.

  5. Create a new page template “page-account” and call the sidebar.

  6. Ensure that the sidebar is show by correctly modifying the sidebar array in config.php and including the conditional tag: array('is_page', array('account')). In this instance I reversed the logic of the conditional tag checks as theres only a few templates which require any sidebar at all.

Does anyone have a better / simpler implementation. This seems like a lot of work to build a simple sidebar nav. I’m probably better off hardcoding it as it will never change.

This post touches on a bunch of sidebar issues that are commonly asked, so I’m hoping we can turn this into a Sidebar sticky of some sort.

Here’s the issues at hand:

How Do I Reverse / Alter the Logic of the Roots Sidebar?

Option #1

Modify line 85 of lib/config.php
return apply_filters('roots_display_sidebar', !$sidebar_config->display);

Option #2

Use a filter

add_filter('roots_display_sidebar', 'roots_sidebar_on_special_page');

function roots_sidebar_on_special_page($sidebar) {
  if (is_page('special-page')) {
    return true;
  }
  return $sidebar;
}

How Do I Show an Alternate (Other Than Primary) Sidebar on Specific Pages?

In templates/sidebar.php you can use a bit of logic to display alternate sidebar for different templates.

<?php 
	if ($post->post_title == 'Account' && is_user_logged_in() == true) {
		dynamic_sidebar('sidebar-woo-account');
	} elseif ($post->post_name =='account' && is_user_logged_in() == false) {

	} else {
	   dynamic_sidebar('sidebar-primary');
	}
?>

Maybe we can compile a list of similar questions and solutions for the community?

Good idea for a sidebar thread, however I think the search function on the forum is pretty decent and has that covered. Also, not to burst your bubble, but I think your subject is very specific and therefore unlikely to become a dedicated and sticky sidebar thread. If such a thread was deemed necessary it would probably be called “The Roots Sidebar Thread” or something similarly generic.

To address your specific question, I think the best place to add a new sidebar and nav menu code is either custom.php or separate custom code files within lib/ which you include inside custom.php.

I think the search function on the forum is pretty decent and has that covered

I suppose if that were true there wouldn’t be so many questions about the sidebar. I’ve seen plenty of them in the old google group, as well as on this discourse forum, and even in the comments on the roots.io blog article that explains the sidebar.

I’ll start compiling the questions, but I guess the reason I had the idea to create a sticky was that my specific application includes 3-4 common questions / problems that people have run into.