Displaying sidebar in x theme or pro for woocommerce single page

hello
i have notieced that sidebar are not being displayed on single product page.
i tried on both x theme and on pro…

i tried what i found from differents previous suject posted by others

none of them work

Hello @khiloc,

Thanks for writing in!

The codes above will not work if you have selected the fullwidth in your global settings, X > Theme Options > Layout & Design > Content Layout. You should select “Content Left, Sidebar Right” or “Sidebar Left, Content Right” so that a sidebar will display in your product page and your single blog posts default layouts.

Hope this helps.

ok
so please be more explicit for me…
Already set before asking for support…
Suppose i did not find those previous post, once this is set, what would you recommend i do to show sidebar on single product page?

Hi There,

My custom code is working fine:

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;

}
add_filter( 'ups_sidebar', 'x_woocommerce_sidebar' );
function x_woocommerce_sidebar($sidebar){
	if( x_is_product() ){
		return 'ups-sidebar-woocommerce';
	}
	return $sidebar;
}

Please make sure you’ve already created a sidebar named as WooCommerce:

If it still doesn’t work, please share us with your admin account so we can take a closer look.

Thank you.

If all you want to do is display a sidebar on WooCommerce single product pages, the short snipped below will do the job. Use the add filter code and sidebar instructions above from Thai if you want to display a sidebar other than your main sidebar. Otherwise it doesn’t seem to be needed. Of course, if your sidebar needs are more complex, this isn’t the solution for you.

function x_get_content_layout() {

    $content_layout = x_get_option( 'x_layout_content' );

      $layout = $content_layout;
      if ( x_is_product() ) {
        $layout = 'content-sidebar';
      }
    
    return $layout;
}

Themeco, let me ( and everyone else who has been going down this rabbit hole ) know if there is some reason this won’t work in the longterm. It is working just fine on WordPress (5.0.3), X-Theme (6.4.6), Cornerstone (3.4.6) with Integrity stack (Site Layout: full width, Content Layout: content left, sidebar right). WooCommerce (3.5.4).

Hi,

Please use the code that my colleagues have provided.

Your code is overriding the theme’s x_get_content_layout function but you only have specified single product layout.

This will break the layout settings of other pages.

Thanks

Hi,

I’ve tried your solution, but I can’t make it work. I am using the latest version of Pro (2.4.6) with a child theme. WP and all plugins are up to date.

I have set “Sidebar Left, Content Right” and the sidebar shows up on all shop pages except for the single product page. I have your snippet in my functions.php in my child theme. But the only thing happening is that it displays an empty sidebar on the right(!).

I supposed I’ve missed something, but what?

Best regards
Bengt

Hey @CyberBengt,

Did you do this step:

If so, did you add widgets to the WooCommerce custom sidebar in Appearance > Widgets?

I’ve tested the what Thai suggested and it works.

If this still doesn’t work, please consult with a third party developer because theme customization is not part of our product support and the guide here was tested to be working.

Thanks.

Thank’s for your answer.

I’ve done all you suggest but still no sidebar. As I mentioned I get the product to the left and a blank space (should be the sidebar) on the right. But my preferences are set to “Sidebar Left, Content Right”.

This problem persist even if I switch back to the original Pro theme (with no customizations) and paste the code in the original theme’s functions.php

I’m using the Integrity stack.

Regards
Bengt

Hi There,

You shouldn’t do that. If you paste the custom code to the parent theme, it will be gone when you update the theme.

Could you 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 login to your site
  • WordPress Admin username / password

Thanks.

I know I shouldn’t change the parent theme. It was just for testing and I have reset it again.

To exclude any plugin conflicts I have disabled all of them (except for WooCommerce itself). But the problem remains.

I didn’t found any “secure button” at first. It was showing after creating the message. A bit confusing.

Hello @CyberBengt,

The single product page has a sidebar now. It is not displaying because the expected sidebar is non existent. You need to update your code:

add_filter( 'ups_sidebar', 'x_woocommerce_sidebar' );
function x_woocommerce_sidebar($sidebar){
	if( x_is_product() ){
		return 'ups-sidebar-produktsidebar';
	}
	return $sidebar;
}

That is because you have a different sidebar slug:

Hope this helps. Please let us know how it goes.

Thank’s a lot for your sharp eyes. There is a lot of code to process and its easy to miss some.

This did the trick. But still there is one thing I don´t understand. When I set “Sidebar Left, Content Right”, the sidebar is still “x-main left” on the single product page, but not in category pages. It’s a bit annoying but its easy to fix with some CSS (as I have done).

Thank’s agin for your help.

Bengt

Hi Bengt,

Please remove your css.

You can change it in the code that was provided by my colleague.

Change this line

 } elseif ( x_is_product() ) {
        $layout = 'content-sidebar';

to this

 } elseif ( x_is_product() ) {
        $layout = 'sidebar-content';

Hope this helps

Hello @CyberBengt,

Does @Paul.r’s response worked out for you?

Please let us know.

It worked perfect.

Thank you all for great support!

Bengt

You’re welcome! :slight_smile:

When I put the code in functions.php I get part of the code at the top of the browser window when I open my site.

Hello @edwinoonk,

Thanks for updating this thread. Could you please insert the complete code you have in your child theme’s functions.php file? We need to check it because you might have inserted an illegal character or invalid code which has cause your issue.

Thank you in advance.

I copied from Thai’s post:

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;

}
add_filter( 'ups_sidebar', 'x_woocommerce_sidebar' );
function x_woocommerce_sidebar($sidebar){
	if( x_is_product() ){
		return 'ups-sidebar-woocommerce';
	}
	return $sidebar;
}