Reputation: 310
I'm trying to change the Woocommerce tags to hierarchical by using:
function wd_hierarchical_tags_register() {
$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',
);
register_taxonomy( 'product_tag', 'product', array(
'labels' => $labels,
'hierarchical' => true,
) );
}
add_action('init', 'wd_hierarchical_tags_register');
After adding this code, the filtering is adding "product_tag" to the URL instead of "product-tag".
How can I fix it?
Upvotes: 1
Views: 1375
Reputation: 253784
You should use instead dedicated filter hook woocommerce_taxonomy_args_product_tag
in a custom hooked function this way:
// Customize Woocommerce 'product_tag' custom taxonomy
add_filter( 'woocommerce_taxonomy_args_product_tag', 'custom_product_tag_args', 10, 1 );
function custom_product_tag_args( $args ){
// Replace with your theme domain name
$domain = 'woocommerce';
$permalinks = wc_get_permalink_structure();
$args['hierarchical'] = true; // <== TRUE
$args['update_count_callback'] = '_wc_term_recount';
$args['label'] = __( 'Product tags', $domain );
$args['labels'] = array(
'name' => __( 'Items', $domain ),
'singular_name' => __( 'Item', $domain ),
'menu_name' => _x( 'Item', 'Admin menu name', $domain ),
'search_items' => __( 'Search items', $domain ),
'all_items' => __( 'All items', $domain ),
'parent_item' => __( 'Parent Item', $domain ),
'parent_item_colon' => __( 'Parent Item:', $domain ),
'edit_item' => __( 'Edit item', $domain ),
'update_item' => __( 'Update item', $domain ),
'add_new_item' => __( 'Add new item', $domain ),
'new_item_name' => __( 'New item name', $domain ),
'popular_items' => __( 'Popular items', $domain ),
'separate_items_with_commas' => __( 'Separate items with commas', $domain ),
'add_or_remove_items' => __( 'Add or remove items', $domain ),
'choose_from_most_used' => __( 'Choose from the most used items', $domain ),
'not_found' => __( 'No items found', $domain ),
);
$args['show_ui'] = true;
$args['query_var'] = true;
$args['capabilities'] = array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
);
$args['rewrite'] = array(
'slug' => $permalinks['tag_rewrite_slug'], <== HERE URL PERMALINK
'with_front' => false,
);
return $args;
}
Code goes in function.php file of the active child theme (or active theme).
Tested and works.
Upvotes: 1