How add css class to woocommerce category from admin panel?

screenshot from photoshop1

hello,
I need a way to add css style for the category of woocommerce from admin panel.

Read More

I need to add input for writing css class, that are assigned to this category in the code.

Help me find a way to solve or may be plug-in.

Thank you

Sorry for my English

Related posts

1 comment

  1. Here’s a good tutorial on how to do this. I’ve adapted the code, but haven’t tested it so be wary of typos.

    Note: WordPress 4.4 is required for the following to work.

    // 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 );
        }
    }
    

Comments are closed.