Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #167030
    gretar
    Participant

    Hello

    I have been trying to set a sidebar to my single Woocommerce product page, example here, http://trsnyr.endor.is/netverslun/lenovo-yoga-2-pro-13-3-spjaldtolva-32gb-android/ but the other threads in the forum with custom code for functions.php do not work.

    Any chance I can get help with this ?

    #167380
    Nabeel A
    Moderator

    Hi Gretar,

    Can you please share the code you’re trying for the sidebar with us, may be we can help you fixing it for your site.

    Thanks!

    #167485
    gretar
    Participant

    This is the code

    if ( ! function_exists( 'x_get_content_layout' ) ) :
      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_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() || x_is_product() ) {
              $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_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;
        }
    
        return $layout;
    
      }
    endif;
    #167871
    Rad
    Moderator

    Hi there,

    The code will only enable the layout with sidebar, there is another code that must display the sidebar.

    Add this code at along with that,

    add_filter( 'ups_sidebar', 'woocommerce_sidebar', 9999 );
    
    function woocommerce_sidebar ( $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;
    
    }

    It will use the sidebar you set at Admin > Appearance > Sidebars that is set for Shop index.

    Then add your widgets at Admin > Appearance > Widgets.

    Hope this helps.

    #168676
    gretar
    Participant

    Can you tell me exactly where to have this code with the other code because when I add this to the functions.php file I only get a blank white screen on my site…

    #168693
    gretar
    Participant

    Sorry, I was missing the last } in the code 🙂

    But the sidebar is still not showing on a single product page. I added a new sidebar with the name Vara and some widgets to it…

    #168886
    Zeshan
    Member

    Hi Gretar,

    Thanks for writing in!

    In that case, would you mind providing us with login credentials 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
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    Thanks!

    #168907
    gretar
    Participant
    This reply has been marked as private.
    #169047
    Zeshan
    Member

    Hi Gretar,

    Thank you for the WordPress credentials!

    The FTP login is necessary to check the backend files, unfortunately, we cannot provide our IP address as we’re working from different locations.

    Meanwhile, you could try following this thread: https://theme.co/x/member/forums/topic/no-sidebar-in-woocommerce/#post-167286

    Thanks!

    #169614
    gretar
    Participant

    I added this code to functions.php

    if ( ! function_exists( 'x_get_content_layout' ) ) :
      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 = 'content-sidebar';
            } else {
              $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
              $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', '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;
    
      }
    endif;
    
    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 );

    But that did not work.

    Can’t you give me 1 IP address from you that you try to connect with ? The backend files should be alright, I have not edited them. I can also see that there is a new version of your theme out now. I will update the theme.

    #169806
    Paul R
    Moderator

    Hi Gretar,

    Sorry that you are still having issues.

    You can try the code below, I have tested it in my local test site and it should work.

    
    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 = 'content-sidebar';
            } else {
              $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
              $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', '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;
    
      }
    
    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 );
    

    Hope that helps.

    #169891
    gretar
    Participant

    Yes ! The sidebar appears now but it’s on the right side of the page on a single product. My site has the sidebar on the left on other pages, I would like that to be the same on single product, what do I need to change ?

    #169907
    gretar
    Participant

    Well, suddenly the sidebar on all pages is on the right now… I would like to have it on the left side of the page.

    #170005
    Christopher
    Moderator

    Hi there,

    Please try this code:

    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 );

    Hope it helps.

    #172603
    gretar
    Participant

    Yes, thank you ! The sidebar is on the left now.

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