- This topic has 19 replies, 6 voices, and was last updated 5 years, 1 month ago by David.
-
AuthorPosts
-
September 20, 2015 at 2:02 pm #138321Peter Islin Nielsen
Hi Tom!
First of all: It’s an absolute pleasure to work with this awesome theme! Everything is so smooth, tidy and well crafted. Keep up the good work π
There is one thing, though, that I can’t wrap my head around: How do I add a custom sidebar to my WooCommerce pages? I don’t want to use one of the standard sidebars that comes with GP, so I’m afraid this will not work in my case. I’ve come as far as to register the custom sidebar in my functions.php, and it also shows up nicely in the WP backend. But what do I do next? I’ve looked a bit at the do_action(‘generate_sidebars’), but I think I need some guidance…
Thanks in advance π
September 21, 2015 at 12:08 am #138375TomLead DeveloperLead DeveloperHi Peter,
Glad you’re enjoying GP π
Are you just wanting to display different widgets on your WooCommerce pages? If so, this plugin should help: https://wordpress.org/plugins/display-widgets/
September 21, 2015 at 12:15 am #138379Peter Islin NielsenHi Tom,
Yeah, it’s by far the best theme I’ve worked with. It beats them all… Better throw you a good review when I get the time π
I’ve already tried out Display Widgets, Widget Context and other plugins of that sort β and it works, but it doesn’t quite get me all the way. It works great with the display/hide widgets on my other pages and post, but on my WooCommerce pages I need a fresh sidebar. Is it possible? It will make it so much easier for my client to maintain that way.
September 21, 2015 at 12:20 am #138382TomLead DeveloperLead DeveloperThanks!
What exactly do you mean by “fresh sidebar”? Using the plugins you listed is probably the easiest way.
This plugin is cool, but I’m not sure if it’s integrated with WooCommerce: https://wordpress.org/plugins/custom-sidebars/
September 21, 2015 at 12:27 am #138387Peter Islin NielsenIn the WP backend I have a lot of standard GP widgets like “Right Sidebar”, “Left Sidebar” and so on. I would like an extra sidebar callede “WooCommerce Sidebar” where I can put all my WooCommerce related stuff to show on all WooCommerce pages. Normally I would register a new widget in my functions.php and display it on a template with
<?php dynamic_sidebar( 'woocommerce_sidebar' ); ?>
, but I can’t quite get it to work in GP.September 21, 2015 at 12:51 am #138413TomLead DeveloperLead DeveloperAh, so you would have to duplicate the sidebar.php or sidebar-left.php files found in the parent theme.
Call it sidebar-woocommerce.php or something. This file would be the same as the others, but would call your custom widget area.
Then duplicate the woocommerce.php file found in the parent theme, and add it to your child theme.
In there, find
do_action('generate_sidebars')
and replace it with:do_action('generate_woocommerce_sidebars')
Then you would add a function like this:
add_action('generate_woocommerce_sidebars','generate_construct_sidebars'); function generate_construct_sidebars() { get_sidebar('woocommerce'); }
That should get you on your way π
September 21, 2015 at 1:22 am #138429Peter Islin NielsenYes, that’s exactly what I want π
But it doesn’t seem to work β I’ve added this to my functions.php:
function arphabet_widgets_init() { register_sidebar( array( 'name' => 'WooCommerce Sidebar', 'id' => 'woocommerce_sidebar', 'before_widget' => '<div>', 'after_widget' => '</div>', 'before_title' => '<h4>', 'after_title' => '</h4>', ) ); } add_action( 'widgets_init', 'arphabet_widgets_init' ); add_action('generate_woocommerce_sidebars','generate_contsruct_sidebars'); function generate_contsruct_sidebars() { get_sidebar('woocommerce'); }
Then I copied the sidebar.php file from GP and copied it to my child theme folder. I renamed it to sidebar-woocommerce.php. After that I copied the woocommerce.php from GP and placed it in my child theme folder as well. I found the
do_action('generate_sidebars')
and changed it todo_action('generate_woocommerce_sidebars')
in woocommerce.php.In the WP backed the widget shows up β and I can interact with it and drag things onto it. But it doesn’t show on the front page.
September 21, 2015 at 9:46 am #138514TomLead DeveloperLead DeveloperInside your sidebar-woocommerce.php file did you edit the call to the correct registered sidebar?
September 21, 2015 at 11:45 pm #138668Peter Islin NielsenAuch, I totally forgot to do that. Thanks, Tom. Premium support once again π
September 22, 2015 at 12:08 am #138670TomLead DeveloperLead DeveloperGlad I could help π
December 3, 2016 at 10:17 am #251049MattTom,
I am trying to do the same thing as Peter was here a year ago, but it looks like the woocommerce.php file has changed since 1.3.22 and there is no do_action(‘generate_sidebars’). How to proceed?
Alternatively, I’ve tried the DisplayWidgets plugin you mentioned and several other custom sidebar plugins without any luck on the WooCommerce pages. I just need a right-sidebar that displays shop-related widgets instead of the blog-related widgets.
Thanks for any help.
December 3, 2016 at 10:27 am #251055TomLead DeveloperLead DeveloperAh yes, GP no longer has a woocommerce.php file and uses hooks instead.
Let’s try something like this…
add_action( 'wp','tu_woocommerce_sidebar' ); function tu_woocommerce_sidebar() { if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) { remove_action( 'generate_sidebars','generate_construct_sidebars' ); add_action( 'generate_sidebars','tu_construct_woocommerce_sidebar' ); } } function tu_construct_woocommerce_sidebar() { get_sidebar( 'woocommerce' ); }
You’ll still need to register the sidebar etc.. However this should replace the need for changing the woocommerce.php file.
Let me know π
December 9, 2016 at 2:12 am #252935ThierryHello,
I have a similar problem, i know that it’s possible with widget but for other reason i search an other way.
In a child theme i create single-newpage.php, content-newpage.php and sidebar-newpage.php
In single-newpage.php i replace
<?php do_action('generate_sidebars'); get_footer();
by
<?php do_action('generate_newpage_sidebars'); get_footer();
It’s correct ?
other thing, what is the code for functions.php ?
thanck you
December 9, 2016 at 10:27 am #253047TomLead DeveloperLead DeveloperThat shouldn’t necessary as this code does that for you: https://generatepress.com/forums/topic/how-do-i-add-a-custom-sidebar/#post-251055
Then you just need to create your widget area with the ID
woocommerce
: https://codex.wordpress.org/Function_Reference/register_sidebarDecember 14, 2016 at 8:17 am #254649Thierrybut why Woocommerce ? i don’t use woo for this website
-
AuthorPosts
- You must be logged in to reply to this topic.