Tagged: x
-
AuthorPosts
-
September 30, 2016 at 8:28 am #1197270
adamzingerParticipantHi,
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,
AdamSeptember 30, 2016 at 10:35 am #1197413
RahulModeratorHey 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.
September 30, 2016 at 11:09 am #1197474
adamzingerParticipantThanks Rahul. How would I specify a particular sidebar I’ve created for this purpose?
Thanks
September 30, 2016 at 1:37 pm #1197655
JoaoModeratorHi 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
October 3, 2016 at 4:18 am #1200242
adamzingerParticipantI 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,
AdamOctober 3, 2016 at 4:50 am #1200273
ChristopherModeratorHi 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.
October 3, 2016 at 8:29 am #1200456
adamzingerParticipantThanks Christopher. Do I need to combine your code with the code from the other thread linked to above?
Thanks,
AdamOctober 3, 2016 at 9:42 am #1200521
RahulModeratorHey 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.
October 3, 2016 at 9:46 am #1200529
adamzingerParticipantHi 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,
AdamOctober 3, 2016 at 11:06 am #1200632
JoaoModeratorHi Adam,
That looks correct.
Let us know if you need further assistance.
Joao
October 3, 2016 at 11:17 am #1200643
adamzingerParticipantMany thanks
October 3, 2016 at 11:41 am #1200678
RahulModeratorYou’re most welcome!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1197270 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
