Z. Dmitry
Z. Dmitry

Reputation: 321

Woocommerce: get list of attributes in WordPress admin panel

I need to display list of Woocommerce Attributes on Woocommerce Add Category Page in WordPress admin panel like a custom fields.

I have a function

    function product_cat_taxonomy_custom_fields($tag) { 
    }

and action

    add_action('product_cat_add_form_fields','product_cat_taxonomy_custom_fields');

How I can get a list of check-boxes with attributes like: color, width, weight, height, etc... but not values of these attributes (blue, green, bronze, white)?

Upvotes: 3

Views: 5081

Answers (2)

Igor Zabavskyi
Igor Zabavskyi

Reputation: 46

add_action( 'product_cat_add_form_fields', 'taxonomy_add_new_meta_field', 10, 2 );

function taxonomy_edit_meta_field($term) {   
  $taxonomies = get_taxonomies();
  foreach ( $taxonomies as $taxonomy ) {
    $is_chacked = ($term_meta[$taxonomy] == 1 ? "checked='checked'" : "");
    echo "<input type='checkbox' ".$is_chacked." value='1' name='term_meta[".$taxonomy."]' />".$taxonomy;
  }
}

Upvotes: 2

Stephanie
Stephanie

Reputation: 41

$attributes =  wc_get_attribute_taxonomies();
    if($attributes) {
        echo '<select><option value="noselection">Choose</option>';
        foreach ( $attributes as $attribute ) {
            echo '<option value="'. $attribute->attribute_name.'">' . $attribute->attribute_label . '</option>';
        }
        echo '</select>';
    }

Upvotes: 4

Related Questions