2016-03-07 85 views
1

screenshot from photoshop1如何從管理面板添加css類到woocommerce類別?

你好,我 需要一種方法來添加CSS樣式woocommerce從管理面板的類別。

我需要添加寫入css類的輸入,這些輸入是在代碼中分配給此類別的。

幫我找一個辦法來解決或者可能是插件。

謝謝

對不起,我的英語

+0

爲什麼你不能使用類別類? – helgatheviking

+0

我需要編寫客戶端將用於他創建的類別的css類。這些類別將是不同的設計。 – zaharbaz

回答

1

下面是關於如何做到這一點的好tutorial。我已經修改了代碼,但沒有測試過,所以要小心輸入錯誤。

注: WordPress 4.4是以下工作所必需的。

// add the fields when the term is created 
add_action('product_cat_add_form_fields', 'add_product_cat_class_field', 10, 2); 

function add_product_cat_class_field($taxonomy) { 
    global $feature_groups; 
    ?><div class="form-field term-group"> 
     <label for="featuret-group"><?php _e('Custom CSS Class', 'my_plugin'); ?></label> 
     <input type="text" class="postform" id="custom-class" name="custom-class" value=""> 
     </select> 
    </div><?php 
} 

// add the fields when the term is being edited 
add_action('product_cat_edit_form_fields', 'edit_product_cat_class_field', 10, 2); 

function edit_product_cat_class_field($term, $taxonomy){ 

    global $feature_groups; 

    // get current group 
    $class = get_term_meta($term->term_id, 'custom-class', true); 

    ?><tr class="form-field term-group-wrap"> 
     <th scope="row"><label for="feature-group"><?php _e('Feature Group', 'my_plugin'); ?></label></th> 
     <td><input type="text" class="postform" id="custom-class" name="custom-class" value="<?php echo esc_attr($class); ?>"></td> 
    </tr><?php 
} 

// save the term meta 
add_action('created_product_cat', 'save_product_cat_class_meta', 10, 2); 

function save_product_cat_class_meta($term_id, $tt_id){ 
    if(isset($_POST['custom-class']) && '' !== $_POST['custom-class']){ 
     $class = sanitize_slug($_POST['custom-class']); 
     add_term_meta($term_id, 'custom-class', $class, true); 
    } 
} 
+0

謝謝!但是我有錯誤: 致命錯誤:調用未定義的函數get_term_meta() 行://獲取當前組 – zaharbaz

+0

['get_term_meta()'](https://developer.wordpress.org/reference/functions/get_term_meta /)是在WordPress 4.4中引入的,因此您可能需要升級。 – helgatheviking

+0

一個問題:如何從meta_value添加body_class? 它不工作: 功能lalka_custom_taxonomy_in_body_class($類){ 如果(is_singular()){ $ = custom_terms get_term_meta($ meta_id, '定製級',真正的); if($ custom_terms){foreach($ custom_terms as $ custom_term){ $ classes [] ='custom-tax-'。 $ custom_term->蛞蝓; } } } return $ classes; } add_filter('body_class','lalka_custom_taxonomy_in_body_class'); – zaharbaz

相關問題