Sidebar on Left Side Woocommerce Product Pages

A few weeks ago I posted about my sidebar issue here: https://theme.co/apex/forum/t/sidebar-on-woocommerce-single-product-pages/1584 That thread appears to be closed since it has been a while so I am creating a new one.

The functions.php code change offered by support in that thread did move the sidebar to the left side as requested, EXCEPT it no longer makes the sidebar appear on woocommerce product pages. The reason I needed the code in the first place was to enable the sidebar on product pages.

So to summarize again, please help me get the sidebar to appear on the LEFT side, on woocommerce product pages AND on all other pages such as blog, custom pages and posts etc (everything except the home page.)

By default, there is no sidebar on any Woocommerce product pages. The below code makes the sidebar appear on woocommerce product pages. I found the code in an old support forum post.

However for some reason this code moves the sidebar to the right side for every page – except on the shop and product pages where it is on the left.

Thank you for the help! I apologize I was not able to reply to the previous support response right away.

Here is the custom functions.php code mentioned above which enables the sidebar on woocommerce product pages, but unfortunately it also moves the sidebar to the right instead of the left.

// Add Sidebar to Product Pages in Woocommerce Store
function x_get_content_layout() {

    $stack          = x_get_stack();
    $content_layout = x_get_option( 'x_' . $stack . '_layout_content', 'content-sidebar' );

    if ( $content_layout != 'full-width' ) {
      if ( is_home() ) {
        $opt    = x_get_option( 'x_blog_layout', 'sidebar' );
        $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_archive() ) {
        if ( x_is_shop() || x_is_product_category() || x_is_product_tag() || x_is_product() ) {
          $layout = 'sidebar-content';
        } else {
          $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        }
      } elseif ( x_is_product() ) {
        $layout = 'sidebar-content';
      } elseif ( x_is_bbpress() ) {
        $opt    = x_get_option( 'x_bbpress_layout_content', 'sidebar' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( x_is_buddypress() ) {
        $opt    = x_get_option( 'x_buddypress_layout_content', 'sidebar' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_404() ) {
        $layout = 'full-width';
      } else {
        $layout = $content_layout;
      }
    } else {
      $layout = $content_layout;
    }

      if ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
        $layout = 'sidebar-content';
      } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
        $layout = 'sidebar-content';
      } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
        $layout = 'full-width';
      }

    return $layout;

      }

    add_filter( 'ups_sidebar', function ( $default_sidebar ) {

      $sidebars = get_option( 'ups_sidebars' );

      foreach ( $sidebars as $id => $sidebar ) {
    if (  x_is_shop() || x_is_product_category() || x_is_product_tag() || x_is_product() ) {
      if ( array_key_exists( 'index-shop', $sidebar ) && $sidebar['index-shop'] == 'on' ) {
        return $id;
      }
    }
      }

      return $default_sidebar;

    }, 9999 );

Hi There,

Could you please provide us with your admin account so we can take a closer look?

Thanks.

I have added the information in the secure note. Thank you, look forward to getting this fixed

Hello There,

Thanks for updating the details. I have managed to correct the issue. I have updated the code:

// Add Sidebar to Product Pages in Woocommerce Store
function x_get_content_layout() {

    $stack          = x_get_stack();
    $content_layout = x_get_option( 'x_' . $stack . '_layout_content', 'sidebar-content' );

    if ( $content_layout != 'full-width' ) {
      if ( is_home() ) {
        $opt    = x_get_option( 'x_blog_layout', 'sidebar' );
        $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_archive() ) {
        if ( x_is_shop() || x_is_product_category() || x_is_product_tag() || x_is_product() ) {
          $layout = 'sidebar-content';
        } else {
          $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        }
      } elseif ( x_is_product() ) {
        $layout = 'sidebar-content';
      } elseif ( x_is_bbpress() ) {
        $opt    = x_get_option( 'x_bbpress_layout_content', 'sidebar' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( x_is_buddypress() ) {
        $opt    = x_get_option( 'x_buddypress_layout_content', 'sidebar' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_404() ) {
        $layout = 'full-width';
      } else {
        $layout = $content_layout;
      }
    } else {
      $layout = $content_layout;
    }

      if ( 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';
      }

    return $layout;

  }

If you need anything else we can help you with, don’t hesitate to open another thread.

1 Like

Working great, thanks!

Glad to hear it!

// Add Sidebar to Product Pages in Woocommerce Store
function x_get_content_layout() {

$stack          = x_get_stack();
$content_layout = x_get_option( 'x_' . $stack . '_layout_content', 'sidebar-content' );

if ( $content_layout != 'full-width' ) {
  if ( is_home() ) {
    $opt    = x_get_option( 'x_blog_layout', 'sidebar' );
    $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_archive() ) {
    if ( x_is_shop() || x_is_product_category() || x_is_product_tag() || x_is_product() ) {
      $layout = 'sidebar-content';
    } else {
      $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
      $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
    }
  } elseif ( x_is_product() ) {
    $layout = 'sidebar-content';
  } elseif ( x_is_bbpress() ) {
    $opt    = x_get_option( 'x_bbpress_layout_content', 'sidebar' );
    $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
  } elseif ( x_is_buddypress() ) {
    $opt    = x_get_option( 'x_buddypress_layout_content', 'sidebar' );
    $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
  } elseif ( is_404() ) {
    $layout = 'full-width';
  } else {
    $layout = $content_layout;
  }
} else {
  $layout = $content_layout;
}

  if ( 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';
  }

return $layout;

}

Hello @Wasser,

Thanks for taking out the time to share the solution with community members. :slight_smile:

Actually I was trying to use the code above and when i use the snippet and then go to a single product page it shows an error “This site is experiencing technical difficulty” works fine on the shop page and category pages just not single product. Not sure why its not working. I have another site with the same code works fine? I tired so other options in the forum but no luck

Hello Eric,

Thanks for updating the thread. :slight_smile:

In that regards to avoid any confusion please create a new ticket. In that please share the details of the issue you are facing and someone from Themeco support staff will assist you.

Thanks for understanding.