Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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:

    widget-login.php

    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:

    widget-login.php

    Otherwise, your functions.php entries look fine.

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

    include_once('woowidgets/widget-cart.php');
    function woocommerce_register_widgets_CUSTOM() {
    register_widget('WooCommerce_Widget_Cart_CUSTOM');
    }
    add_action('widgets_init', 'woocommerce_register_widgets_CUSTOM');

    …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.

    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:

    functions.php

    include_once('woowidgets/widget-cart.php');
    function woocommerce_register_widgets_CUSTOM() {
    register_widget('WooCommerce_Widget_Cart_MJ');
    }
    add_action('widgets_init', 'woocommerce_register_widgets_CUSTOM');

    /woowidgets/widget-cart.php
    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.

Viewing 5 replies - 1 through 5 (of 5 total)