2014-06-19 64 views
0

我想一對類添加到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); 
} 
+0

濾波器'widget_display_callback'返回'$設置變量。所以你可以使用這個過濾器。我也沒有找到任何方法來做到這一點,是嗎?D –

+0

這可能會有所幫助,我猜:http://stackoverflow.com/questions/12351603/wordpress-add-配置選項對所有插件的設置 –

回答

-1

嘗試:

function changeclass() { 
    WC_Widget_Product_Categories->woo_widget_cssclass= 'whatever'; 
} 

add_action('init', 'changeclass'); 

,如果它不工作,你需要去查了一下更多,上面的代碼被吸引到哪裏? (它的一個類,所以這將是ADD_ACTION( '初始化' 陣列($此, 'functionname');(概率函數WP_WIDGET

在這裏看到可能鉤:http://codex.wordpress.org/Plugin_API/Action_Reference

+0

不幸的是,這將引發一個「解析錯誤:語法錯誤,意外‘ - >’(T_OBJECT_OPERATOR)在/和home1 /寶/的public_html /櫃/可溼性粉劑內容/主題/最好的/第43行的functions.php「錯誤 – Fireflight

+0

抱歉用主動對象替換WC_Widget_Product_Categories搜索新的WC _Widget_Product_Categories在代碼中,或者如果它的一個靜態對象WC_Widget_Product_Categories :: woo_widget_cssclass等,不幸的是我不能看到這個! – David

相關問題