Support » Plugins » Possible to overwrite a WooCommerce Widget?

  • Hello,

    I was working on a website with this WooCommerce WP plugin and i was asking myself would it be possible to overwrite a default WooCommerce Widget template?

    I know i can overwrite the template files by copy-/pasting them from my plugin folder to my theme folder, I’ve done that.
    But now i would like to use the Featured product Widget and change the core code a little bit so i can use that Widget inside a homepage slideshow.

    Only problem i face is this Widget (widget_featured_products.php) is inside the plugin folder so it will be overwritten by the next update from WooCommerce if i make any changes to that file.


Viewing 13 replies - 1 through 13 (of 13 total)
  • Smith


    did you work out how to fix this issue?

    Here’s what I did — it’s a roundabout way, but I couldn’t find any other solution. I made a separate folder under my theme called ‘woowidgets’ and then copied over the ones I needed from the ‘/plugins/woocommerce/widgets’ folder.

    Then, I copied the function that loads/initializes the widgets from the ‘/plugins/woocommerce/widgets/widget-init.php’ file. I had to modify the naming conventions so that I didn’t try to make a second call to that same function.

    Finally I updated my theme’s functions.php file to include the new initialization string and include to reference the widget file within my newly created widget folder. Now I’m free to modify that widget as a custom file and it will appear on my widget screen in the UI alongside the original Woocommerce-supplied one. I’ll just drag my widget into the sidebar instead. Here’s more or less what my structure looked like afterwards:


    function woocommerce_register_widgets_CUSTOM() {
    add_action('widgets_init', 'woocommerce_register_widgets_CUSTOM');

    I replaced any instance of ‘WooCommerce_Widget_Cart’ with ‘WooCommerce_Widget_Cart_CUSTOM’

    I also edited line 26 ‘$this->woo_widget_name = __(‘MY CUSTOM CART WIDGET’, ‘woocommerce’ );’

    Lastly, I edited line 31 to give the cart a new name:
    /* Create the widget. */
    $this->WP_Widget(‘shopping_cart_CUSTOM’, $this->woo_widget_name, $widget_ops);

    It all seems to be working pretty well, just a lot of copying, pasting and editing. let me know if it works out for you if you find a better/cleaner solution.

    …forgot to mention that at least going about it this route ensures that with a WooCommerce update, nothing will be overwritten. The only danger is a major code change that could break it, but I don’t foresee that happening any time soon.

    Correction on that functions.php, I typed that in hastily, it should actually be this:

    function woocommerce_register_widgets_CUSTOM() {
    add_action('widgets_init', 'woocommerce_register_widgets_CUSTOM');

    Hi there,

    This is the solution i’ve been hunting for!

    However, i cant get it to work! I’m getting a server error 🙁

    I’m trying to edit the login widget so i have copied that into a new woowidget folder in my theme.
    I’ve editied all instances of WooCommerce_Widget_Login to WooCommerce_Widget_Login_CUSTOM in the widget-login.php file

    edited this:
    $this->woo_widget_name = __('WooCommerce CUSTOM Login', 'woocommerce' );

    and this:

    $this->WP_Widget('woocommerce_login_CUSTOM', $this->woo_widget_name, $widget_ops);

    and added this to my functions.php file:

    function woocommerce_register_widgets_CUSTOM() {
    add_action('widgets_init', 'woocommerce_register_widgets_CUSTOM');

    unfortunately its breaking the site though!

    any idea whats wrong?
    Many thanks in advance.

    I think you might just be missing something lower down in the code of that particular file — around line 210. Try this file, I tweaked the original one with your CUSTOM name:


    Otherwise, your functions.php entries look fine.

    Oops — I lied — I grabbed a modified version that I had made for myself. Here’s the original WOO-provided file, but modified based on your CUSTOM naming:


    Hi mbizfreak,

    I really think your roundabout way is a solution for an issue I have.
    But I do have one question, before I mess thing up.

    What do you mean with:

    “I had to modify the naming conventions so that I didn’t try to make a second call to that same function”?

    How did you modified what? Could you please explain this?


    What I want to do is change the size of the product image in the cart widget. I just want the image to be a tiny thumbnail (about 45×45 pixels).

    I found this line in the widget_cart.php:
    echo $_product->get_image();

    But how can I change the style or size of this image?
    Any suggestions? Thx!

    Interesting, how would you add two or three widgets?

    PS: in the functions.php I meant.

    I had a go, and it seems to work well. Thank you.

    This worked quite well for me too. Seems like the best solution I have found so far.

    Yeah, it’s pretty good — I tested it, although it’s on the back burner atm, I’ll get back to it. How/where is mbizfreak? Thanks again.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Possible to overwrite a WooCommerce Widget?’ is closed to new replies.