我想一對類添加到Woocommerce產品類別的Widget。爲了確保我不會破壞任何更新,我想在不編輯原始源代碼的情況下執行此操作,或者不必創建新的替換小部件。我怎麼能一個CSS類添加到現有的Woocommerce/WordPress的插件
從我收集的,widget_display_callback
應該能夠做我需要的東西,但documentation真的很稀疏(實際上並不存在)。所以我不確定如何拉取包含應用於小部件的css類名的設置。
我目前的代碼在下面,顯然不起作用。任何建議將非常感激。
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;
}
這就是我認爲是在class-wc-widget-product-categories.php
文件中的相關代碼片段:
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);
}
濾波器'widget_display_callback'返回'$設置變量。所以你可以使用這個過濾器。我也沒有找到任何方法來做到這一點,是嗎?D –
這可能會有所幫助,我猜:http://stackoverflow.com/questions/12351603/wordpress-add-配置選項對所有插件的設置 –