- This topic has 11 replies, 4 voices, and was last updated 6 years, 12 months ago by
Swizzonic AG.
-
AuthorPosts
-
July 9, 2018 at 1:18 am #618996
neverything
Hi, I am using GP Premium with the WooCommerce plugin, and I want to display a WooCommerce-specific sidebar on my Woo archive pages. I would prefer to not use another plugin to filter widgets, or anything like that. (I know this topic has come up a few times here in the support forums, but I went through all the past solutions and can’t seem to get it to work.)
I have the new Woo-only sidebar registered and showing correctly (yay) but the regular right sidebar is also showing above it. I have narrowed the problem down to the first 3 lines below:
// this code seems to have no effect... if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) { remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 ); } // this code below works great and adds my Woo sidebar correctly add_action( 'woocommerce_sidebar', function () { get_sidebar( 'woocommerce' ); } );
My theory is that the GP Premium Woo plugin is overriding and doing its own sidebar display. I found the
generate_sidebar_layout
filter and played with that but no luck. How can I get just my Woo sidebar to show on my Woo is_archive() pages, and not the regular sidebar at all?Thanks very much,
Ericp.s. I see so many requests for a WooCommerce-specific sidebar, it would be cool if this was an option in the GP Premium plugin… turn it on and it shows up in widgets, ready to roll.
July 9, 2018 at 5:35 am #619137David
StaffCustomer SupportHi there
can you provide a link to the site? You can edit your original post and use the Site URL field which is for admins only.
July 17, 2018 at 6:27 am #625656Swizzonic AG
Hi David, this is Eric on a different account – I’ve edited the post above to include the site URL (it is on a staging server) but you’ll need a user account to get in. How can I get you those credentials? Thanks.
July 17, 2018 at 8:29 am #625841Leo
StaffCustomer SupportYou can send it through Account Issue here:
https://generatepress.com/contact/Make sure to reference the topic URL.
July 18, 2018 at 2:28 am #626366Swizzonic AG
Ok! Just sent. Thanks for your support. E
July 18, 2018 at 10:14 am #626792David
StaffCustomer SupportHi Eric,
ok just spotted that you’re trying to disable a sidebar that GP doesn’t generate in that first function – that is we don’t have a woocommerce_sidebar. What is being displayed is the GP right-sidebar. This article here has a filter for changing the layout, the first example is for a woocmmerce setup – just need to return no-sidebar.
https://docs.generatepress.com/article/sidebar-layout/
Let me know.
July 24, 2018 at 12:51 am #631270Swizzonic AG
Hi David, thank you for this reply, sorry it has taken me a few days to track it down and try it out.
I am not sure I completely understand what you are saying. 🙂
In my functions I register a new sidebar called ‘woocommerce’. How can I hook into GP to tell it to draw this sidebar on the Woo is_archive() page, but not anywhere else?
I tried adapting the code snippet you mentioned, but now, the normal sidebar is showing up on the Blog page (good), and on my Woo page, I get both the normal sidebar (bad) and a weird phantom sidebar with just search and archives (??). I don’t see my custom woocommerce sidebar anywhere, but on my woo page I am swimming in sidebars. 🙂
I just pushed out a new deploy with that changed code snippet. Any chance you can take a peek? And feel free to look at what I did in functions.php. You’ll see where I create the custom woocommerce sidebar in there, too.
Thank you for your help…
best
EricJuly 24, 2018 at 6:45 am #631456David
StaffCustomer SupportApologies, think i am having a meltdown lol – this is a lot more complicated then it looks. Have you thought of using a plugin like:
July 25, 2018 at 12:05 am #632141Swizzonic AG
Hi David, heh, thank you for the reply. I could use a plugin but that seems like major overkill. I can write the code to draw a sidebar, and I can easily limit that to woocommerce archive pages only. The issue is where to hook in with GP. Maybe I can kill the GP Premium plugin that plays with sidebars and that will let me do it. I’ll let ya know what happens….
July 25, 2018 at 2:12 am #632189Swizzonic AG
Ultimately it was easier just to override this GP function and put this into my child theme functions.php… But I would strongly recommend you guys add a hook for in here to let the user add their own sidebar easily! 🙂
// override this function function generate_construct_sidebars() { $layout = generate_get_layout(); // When to show the right sidebar. $rs = [ 'right-sidebar', 'both-sidebars', 'both-right', 'both-left' ]; // When to show the left sidebar. $ls = [ 'left-sidebar', 'both-sidebars', 'both-right', 'both-left' ]; // If left sidebar, show it. if ( in_array( $layout, $ls ) ) { get_sidebar( 'left' ); } if ( function_exists( 'is_woocommerce' ) && is_woocommerce() && is_archive() ) { get_sidebar( 'woocommerce' ); } elseif ( in_array( $layout, $rs ) ) { // If right sidebar, show it. get_sidebar(); } }
July 25, 2018 at 5:40 am #632338David
StaffCustomer SupportHi there, glad you found a solution and thank you for sharing. Nice method.
I believe Tom has something planned in this area.July 30, 2018 at 1:27 am #635759Swizzonic AG
Review ✔ done
-
AuthorPosts
- You must be logged in to reply to this topic.