I'm trying to extend the woocommerce class used to create the product categories widget in my own plugin which adds a new taxonomy for woo commerce products called "departments".
When I extend WP_Widget everything works just fine and I see a new widget that I can add in Appearance->Widgets. However, when I'm trying to extend WC_Widget or WC_Widget_Product_Categories I simply don't see a new widget, even though I'm not getting any php errors.
Here's what I have which doesn't work:
//get the base classes
if(!class_exists('WC_Widget_Product_Categories')) {
require_once ABSPATH . 'wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-widget.php';
require_once ABSPATH . 'wp-content/plugins/woocommerce/includes/widgets/class-wc-widget-product-categories.php';
}
/**
* Product departments widget class.
*
* @extends WC_Widget_Product_Categories
*/
class WC_Widget_Product_Departments extends WC_Widget_Product_Categories {
/**
* Constructor.
*/
public function __construct() {
$this->widget_cssclass = 'woocommerce widget_product_departments';
$this->widget_description = __( 'A list or dropdown of product departments.', 'woocommerce' );
$this->widget_id = 'woocommerce_product_departments';
$this->widget_name = __( 'Shop Departments', 'woocommerce' );
parent::__construct();
}
}
and in my main plugin file:
add_action( 'widgets_init', 'register_department_widgets', 15 );
function register_department_widgets() {
register_widget( 'WC_Widget_Product_Departments' );
}
However, if I change the class being extended it does work:
class WC_Widget_Product_Departments extends WC_Widget
What am I doing wrong if I want to extend the WC_Widget_Product_Categories
class?