get_var( $wpdb->prepare( "SELECT attribute_id FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = %s", $attribute_slug ) ); if (!$exists) { wc_create_attribute([ 'name' => $attribute_name, 'slug' => $attribute_slug, 'type' => 'select', 'order_by' => 'menu_order', 'has_archives' => false, ]); // Clear cache Woo delete_transient('wc_attribute_taxonomies'); } if (!taxonomy_exists($taxonomy)) { register_taxonomy( $taxonomy, 'product', [ 'label' => $attribute_name, 'public' => false, 'hierarchical' => false, 'show_ui' => true, 'query_var' => true, 'rewrite' => false, // Cho phép gán trong Product data → Attributes 'meta_box_cb' => 'post_tags_meta_box', ] ); } foreach (['on_store', 'links'] as $term) { if (!term_exists($term, $taxonomy)) { wp_insert_term($term, $taxonomy); } } });