Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1197270
    adamzinger
    Participant

    Hi,

    How do I add a right sidebar to the WooCommerce product pages? I want to create a new sidebar and add a widget to it so it only displays on product pages. I’m using the Renew theme.

    Thanks,
    Adam

    #1197413
    Rahul
    Moderator

    Hey There,

    Thanks for writing in!

    Kindly walk-through this thread :

    https://community.theme.co/forums/topic/add-sidebar-to-single-product-page-woocommerce/

    Let us know if this helps!

    Thank you.

    #1197474
    adamzinger
    Participant

    Thanks Rahul. How would I specify a particular sidebar I’ve created for this purpose?

    Thanks

    #1197655
    Joao
    Moderator

    Hi There,

    I am not sure if I understand your question, but you can add elements to your sidebar on Appereance > Widgets > Sidebar.

    Hope that helps

    Joao

    #1200242
    adamzinger
    Participant

    I mean if I create a new sidebar called ‘Product Sidebar’ from Appearance > Sidebars how would I make sure that the individual product pages use this sidebar instead of the ‘Main Sidebar’?

    Thanks,
    Adam

    #1200273
    Christopher
    Moderator

    Hi there,

    Please add following code in child theme’s functions.php file :

    add_filter( 'ups_sidebar', 'product_sidebar', 9999 );
    
    function product_sidebar ( $default_sidebar ) {
    if ( x_is_product() ) return 'the-id-of-the-sidebar'; //Must match the ID of your target sidebar
    return $default_sidebar;
    }

    Hope it helps.

    #1200456
    adamzinger
    Participant

    Thanks Christopher. Do I need to combine your code with the code from the other thread linked to above?

    Thanks,
    Adam

    #1200521
    Rahul
    Moderator

    Hey There,

    Thanks for writing back!

    No, you don’t need to combine the given codes. Use them separately and see if it works.

    Let us know how it goes!

    Thank you.

    #1200529
    adamzinger
    Participant

    Hi Christopher,

    I’ve added the code below to my child theme’s functions.php. Can you please check the following and let me know if it is okay? It looks like it is working as I need (sidebar on the left for all pages except product pages that have my custom sidebar on the right)…

    if ( ! function_exists( 'x_get_content_layout' ) ) :
      function x_get_content_layout() {
    
        $stack          = x_get_stack();
        $content_layout = x_get_option('x_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_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','sidebar' );
              $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
            } else {
              $opt    = x_get_option( 'x_archive_layout', '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 ( x_is_product() ) {
              $layout = 'content-sidebar'; //or sidebar-content
            } else {
              $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
              $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
            }
    
        return $layout;
    
      }
    endif;
    
    add_filter( 'ups_sidebar', 'product_sidebar', 9999 );
    
    function product_sidebar ( $default_sidebar ) {
    if ( x_is_product() ) return 'ups-sidebar-product-sidebar'; //Must match the ID of your target sidebar
    return $default_sidebar;
    }
    

    Thanks,
    Adam

    #1200632
    Joao
    Moderator

    Hi Adam,

    That looks correct.

    Let us know if you need further assistance.

    Joao

    #1200643
    adamzinger
    Participant

    Many thanks

    #1200678
    Rahul
    Moderator

    You’re most welcome!

  • <script> jQuery(function($){ $("#no-reply-1197270 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>