How to Add Custom Taxonomy To Woocommerce Plugin

You have to do:

add_action( 'init', 'custom_taxonomy_Item' );

Because:

Use the init action to call this function. Calling it outside of an action can lead to troubles.

see codex page register_taxonomy. Besides that :

Better be safe than sorry when registering custom taxonomies for custom post types. Use register_taxonomy_for_object_type() right after the function to interconnect them. Else you could run into minetraps where the post type isn’t attached inside filter callback that run during parse_request or pre_get_posts.

So better add:

register_taxonomy_for_object_type( 'item', 'product' );

Additionally to reading the linked codex pages you could take a look at:

All this together should get you started.


Edit:

Like I said in the comment, it’s working for me, this is the Code:

add_action( 'init', 'custom_taxonomy_Item' );
function custom_taxonomy_Item()  {
$labels = array(
    'name'                       => 'Items',
    'singular_name'              => 'Item',
    'menu_name'                  => 'Item',
    'all_items'                  => 'All Items',
    'parent_item'                => 'Parent Item',
    'parent_item_colon'          => 'Parent Item:',
    'new_item_name'              => 'New Item Name',
    'add_new_item'               => 'Add New Item',
    'edit_item'                  => 'Edit Item',
    'update_item'                => 'Update Item',
    'separate_items_with_commas' => 'Separate Item with commas',
    'search_items'               => 'Search Items',
    'add_or_remove_items'        => 'Add or remove Items',
    'choose_from_most_used'      => 'Choose from the most used Items',
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => true,
);
register_taxonomy( 'item', 'product', $args );
register_taxonomy_for_object_type( 'item', 'product' );
}

Leave a Comment