I'd like to add a pair of classes to the Woocommerce Product Categories Widget. In order to ensure I don't break any updates, I'd like to do so without editing the original source code, or having to create a new replacement widget.
From what I've gathered,
should be able to do what I need, but the <a href="https://codex.wordpress.org/index.php?title=Plugin_API/Filter_Reference/widget_display_callback" rel="nofollow">documentation</a> is really sparse (actually non-existant). So I'm not really certain how to pull the setting that contains the css classnames that are applied to the widget.
My current code is below, which is obviously not working. Any suggestions would be really appreciated.
Here's what I think is the relevant code snippet in the
file:
From what I've gathered,
Code:
widget_display_callback
My current code is below, which is obviously not working. Any suggestions would be really appreciated.
Code:
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;
}
Here's what I think is the relevant code snippet in the
Code:
class-wc-widget-product-categories.php
Code:
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);
}