如何从管理面板中将css类添加到woocommerce类别?

时间:2016-03-07 20:48:47

标签: wordpress wordpress-plugin woocommerce

screenshot from photoshop 1

您好, 我需要一种方法来为管理面板中的woocommerce类别添加css样式。

我需要添加用于编写css类的输入,这些输入在代码中分配给此类别。

帮我找到解决方法或插件。

谢谢

抱歉我的英文

1 个答案:

答案 0 :(得分: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 );
    }
}
相关问题