public static function add_new_attribute()
{
check_ajax_referer('add-attribute', 'security');
if (current_user_can('manage_product_terms')) {
$taxonomy = esc_attr($_POST['taxonomy']);
$term = wc_clean($_POST['term']);
if (taxonomy_exists($taxonomy)) {
$result = wp_insert_term($term, $taxonomy);
if (is_wp_error($result)) {
wp_send_json(array('error' => $result->get_error_message()));
} else {
$term = get_term_by('id', $result['term_id'], $taxonomy);
wp_send_json(array('term_id' => $term->term_id, 'name' => $term->name, 'slug' => $term->slug));
}
}
}
die(-1);
}