screenshot from photoshop1如何从管理面板添加css类到woocommerce类别?
你好,我 需要一种方法来添加CSS样式woocommerce从管理面板的类别。
我需要添加写入css类的输入,这些输入是在代码中分配给此类别的。
帮我找一个办法来解决或者可能是插件。
谢谢
对不起,我的英语
screenshot from photoshop1如何从管理面板添加css类到woocommerce类别?
你好,我 需要一种方法来添加CSS样式woocommerce从管理面板的类别。
我需要添加写入css类的输入,这些输入是在代码中分配给此类别的。
帮我找一个办法来解决或者可能是插件。
谢谢
对不起,我的英语
下面是关于如何做到这一点的好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);
}
}
谢谢!但是我有错误: 致命错误:调用未定义的函数get_term_meta() 行://获取当前组 – zaharbaz
['get_term_meta()'](https://developer.wordpress.org/reference/functions/get_term_meta /)是在WordPress 4.4中引入的,因此您可能需要升级。 – helgatheviking
一个问题:如何从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
为什么你不能使用类别类? – helgatheviking
我需要编写客户端将用于他创建的类别的css类。这些类别将是不同的设计。 – zaharbaz