Looking for a way to add additional classes to the Woocommerce Product Categories Widget without tampering with the original source code or creating a replacement widget? The widget_display_callback
seems like the way to go, but the available documentation is quite scarce.
The following code snippet attempts to achieve this, but it's not functioning as expected. Any insights or suggestions would be highly appreciated.
add_filter( 'widget_display_callback', 'add_classes', 10, 3 );
function add_classes($settings, $widget, $args) {
if (get_class($widget) == 'WC_Widget_Product_Categories') {
$widget_ops['classname'] .= " hidden-phone hidden-tablet";
}
return $widget_ops;
}
This excerpt from the
class-wc-widget-product-categories.php
file might hold relevant information:
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_Widget_Product_Categories extends WP_Widget {
var $woo_widget_cssclass;
var $woo_widget_description;
var $woo_widget_idbase;
var $woo_widget_name;
var $cat_ancestors;
var $current_cat;
/**
* constructor
*
* @access public
* @return void
*/
function WC_Widget_Product_Categories() {
/* Widget variable settings. */
$this->woo_widget_cssclass = 'woocommerce widget_product_categories';
$this->woo_widget_description = __( 'A list or dropdown of product categories.', 'woocommerce' );
$this->woo_widget_idbase = 'woocommerce_product_categories';
$this->woo_widget_name = __( 'WooCommerce Product Categories', 'woocommerce' );
/* Widget settings. */
$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
/* Create the widget. */
$this->WP_Widget('product_categories', $this->woo_widget_name, $widget_ops);
}