Steps to have specific sidebar for woocommerce and learndash

Hi there,
I have searched the forum and found some hints but I am still confused.

what are all the steps and settings in pro to have:

  • custom sidebar for learndash (courses, lessons, etc)
  • custom sidebar for woocommerce (single products, shops etc)

Would you be so kind to describe steps and settings starting from the theme options and on?

Thank you :slight_smile:

Hi There,

First, please install and activate the child theme: https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57

Please try adding this custom code under functions.php file locates in your child theme:

add_filter('x_option_x_layout_content', 'add_sidebar_learndash',999);
function add_sidebar_learndash($layout) {  
    if ( 'product' || 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() )  {      
       $layout = "content-sidebar";
   }
  return $layout;
}

Hope it helps :slight_smile:

Hi Thai,
thank you for your reply.
I confirm I am already working in a child theme.

  1. this is about the sidebar for learndash, right? had already tried this in the past days and worked.
    I then got stuck when I tried to assign a custom sidebar (https://theme.co/apex/forum/t/features-unlimited-sidebars/95) can you guide me in the right direction?

  2. What about woocommerce?
    Theme options: should some options in woocommerce section be activated? If yes, which ones exactly?
    Is there any code to add to functions.php as well?

Hi,

The code provided is to change the layout of product page and leardash pages to content sidebar.
But to assign a sidebar to it, you need to add this code.

function assign_my_sidebar($sidebar){ 
       if ( 'product' || 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() )  {      
           return 'ups-sidebar-shop';        
       }    
  return $sidebar;
}
add_filter( 'ups_sidebar', 'assign_my_sidebar');

Change shop with the name of you sidebar.

So your complete code will be.

add_filter('x_option_x_layout_content', 'add_sidebar_learndash',999);
function add_sidebar_learndash($layout) {  
    if ( 'product' || 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() )  {      
       $layout = "content-sidebar";
   }
  return $layout;
}

function assign_my_sidebar($sidebar){ 
       if ( 'product' || 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() )  {      
           return 'ups-sidebar-shop';        
       }    
  return $sidebar;
}
add_filter( 'ups_sidebar', 'assign_my_sidebar');

Hope that helps

Hi, it works for learndash but does not work for single product pages.
Actually, those pages seem to be stuck on full width layout even after the new code in functions.php (see link in secure note)

Hi @rubius

To check your current setup, please provide us with WordPress Dashboard login details in a “Secure Note” so we can investigate this issue.

Thanks.

Please find in the secure note your login details.

The code in functions.php for the sidebar “shop” is:

   /* LEARNDASH INIZIO */
	
add_filter('x_option_x_layout_content', 'add_sidebar_learndash',999);
function add_sidebar_learndash($layout) {  
    if ( 'product' || 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() )  {      
       $layout = "content-sidebar";
   }
  return $layout;
}
	
function assign_my_sidebar($sidebar){ 
       if ( 'product' || 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() )  {      
           return 'ups-sidebar-shop';        
       }    
  return $sidebar;
}
add_filter( 'ups_sidebar', 'assign_my_sidebar');

Hello There,

I have logged in and modified the code. I used this code:

f ( ! function_exists( 'x_get_content_layout' ) ) :
  function x_get_content_layout() {

    $content_layout = x_get_option( 'x_layout_content' );

    if ( $content_layout != 'full-width' ) {
      if ( is_home() ) {
        $opt    = x_get_option( 'x_blog_layout' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_singular( 'post' ) ) {
        $meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
        $layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
      } elseif ( x_is_portfolio_item() ) {
        $layout = 'full-width';
      } elseif ( x_is_portfolio() ) {
        $meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
        $layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
      } elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
        $layout = 'content-sidebar';
      } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
        $layout = 'sidebar-content';
      } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
        $layout = 'full-width';
      } elseif ( is_archive() ) {
        if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
          $opt    = x_get_option( 'x_woocommerce_shop_layout_content' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        } else {
          $opt    = x_get_option( 'x_archive_layout' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        }
      } elseif ( x_is_product() ) {
        $layout = 'content-sidebar';
      } elseif ( x_is_bbpress() ) {
        $opt    = x_get_option( 'x_bbpress_layout_content' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( x_is_buddypress() ) {
        $opt    = x_get_option( 'x_buddypress_layout_content' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_404() ) {
        $layout = 'full-width';
      } else {
        $layout = $content_layout;
      }
    } else {
      $layout = $content_layout;
    }

    return $layout;

  }
endif;

/* LEARNDASH INIZIO */
	/*aggiunge la sidebar solo ai posts di learndash */
add_filter('x_option_x_layout_content', 'add_sidebar_learndash',999);
function add_sidebar_learndash($layout) {  
    if ( 'sfwd-courses' == get_post_type() || 'sfwd-lessons' == get_post_type() || 'sfwd-quiz' == get_post_type() || 'sfwd-topic' == get_post_type() || 'sfwd-certificates' == get_post_type() )  {      
       $layout = "content-sidebar";
   }
  return $layout;
}
	/* sostituisce alla sidebar generica quella specifica che ho creato un sidebars e che ha id ups-sidebar-learndash */
function assign_my_sidebar($sidebar){ 
	if ( is_product() ) {
		return 'ups-sidebar-shop';
	}
    
	if ( 'sfwd-courses' == get_post_type() || 'sfwd-lessons' == get_post_type() || 'sfwd-quiz' == get_post_type() || 'sfwd-topic' == get_post_type() || 'sfwd-certificates' == get_post_type() )  {      
           return 'ups-sidebar-learndash';        
    }    
  return $sidebar;
}
add_filter( 'ups_sidebar', 'assign_my_sidebar');

Please check your site now.

It works. Thank you!

You’re welcome!
Thanks for letting us know that it has worked for you.

Hi I tried doing this as well on my site and although it shows the sidebar on the learndash pages, the sidebar has disappeared on the blog and blog post pages.

Any idea what I did wrong?

Code is as below:

add_filter('x_option_x_layout_content', 'add_sidebar_learndash',999);
function add_sidebar_learndash($layout) {  
    if ( 'product' || 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() )  {      
       $layout = "content-sidebar";
   }
  return $layout;
}

function assign_my_sidebar($sidebar){ 
       if ( 'product' || 'sfwd-courses' || 'sfwd-lessons' || 'sfwd-quiz' || 'sfwd-topic' || 'sfwd-certificates' == get_post_type() )  {      
           return 'ups-sidebar-course';        
       }    
  return $sidebar;
}
add_filter( 'ups_sidebar', 'assign_my_sidebar');

Hi @lwliang1,

Please create a separated ticket then provide us with login credentials(by clicking on the Secure Note button at the bottom) so we can take a closer look? To do this, you can make a post with the following info:

  • Link to your site
  • WordPress Admin username / password

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.