我试图通过针对Woocommerce中的产品帖子类型,为Woocommerce添加自定义分类法。我使用了以下代码并将其添加到functions.php
我没有收到任何错误消息,但分类法也没有显示在Woocommerce中。你能告诉我怎么做吗?或者我做错了什么?
<?php
// Register Custom Taxonomy
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 );
}
?>
Update
<?php
add_action( \'init\', \'custom_taxonomy_Item\' );
// Register Custom Taxonomy
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_for_object_type( \'item\', \'product\', $args );
}
?>