Pro: Sidebar on single products Woocommerce

In my Pro site, single Woocommerce product pages have no sidebar and there’s not even space for one as the product has gone full width. I have a sidebar by default everywhere else on the site. I can’t find a setting to configure this. Am I missing something? Thanks!

Hi,

Thanks for writing in!

It has no sidebar by design.
To add sidebar to your product pages, you can add the code below in your child theme’s functions.php file.

function add_sidebar_postt($layout){
    if(is_product()){
        $layout = "content-sidebar";
    }
    return $layout;
}

add_filter('x_option_x_layout_content', 'add_sidebar_postt',999);

Hope that helps

1 Like

Didn’t work sorry. Will share my site details privately.

Hi,

Please try this code instead.

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;

  }

Hope that helps

1 Like

Brilliant, works, but now it’s got the sidebar on the right but everywhere else I have it on the left so can I trouble you for a little more code to make that happen please?

Hi There,

Thanks again for writing in!
Please use this CSS to make the sidebar in left.

.single-product .x-main.left {
float: right !important;
}
.single-product .x-sidebar.right {
float: left !important;
}

Add this to Pro-> theme option -> Global CSS
Hope this helps!

1 Like

Brilliant - thanks :slightly_smiling_face:
And so I now have a sidebar on the left, which is great, but how can I make a sidebar appear there? I have already created a sidebar and set it to show for the children of the parent page /shop/ and all single products fall under that…

Hi,

To assign a sidebar to all your product page, you can add the code below in your child theme’s functions.php file.

function assign_product_sidebar($sidebar){
 
        if (is_product()){
             return 'ups-sidebar-s-shop';        
         }
    
  return $sidebar;
}
add_filter( 'ups_sidebar', 'assign_product_sidebar');

Hope that helps.

1 Like

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