How to make woocommerce product tags hierarchical?
Tested on woocommerce 3.0.4
function my_woocommerce_taxonomy_args_product_tag( $array ) { $array['hierarchical'] = true; return $array;};add_filter( 'woocommerce_taxonomy_args_product_tag', 'my_woocommerce_taxonomy_args_product_tag', 10, 1 );
Found the solution, here it is if someone is looking to do the same:
function reregister_taxonomy_pro_tags() { # the post types that the taxonomy is registered to $post_types = array('product'); # set this to the taxonomy name $tax_name = 'product_tag'; # load the already created taxonomy as array so we can # pass it back in as $args to register_taxonomy $tax = (array)get_taxonomy($tax_name); if ($tax) { # adjust the hierarchical necessities $tax['hierarchical'] = true; $tax['rewrite']['hierarchical'] = true; # adjust the hierarchical niceties (these could be ignored) $tax['labels']['parent_item'] = sprintf(__("Parent %s"), $tax->labels->singular_name); $tax['labels']['parent_item_colon'] = sprintf(__("Parent %s:"), $tax->labels->singular_name); # cast caps to array as expected by register_taxonomy $tax['capabilities'] = (array)$tax['cap']; # cast labels to array $tax['labels'] = (array)$tax['labels']; # register the taxonomy with our new settings register_taxonomy($tax_name, array('product'), $tax); }}
init action with a late priority so other taxonomies are loaded
add_action('init', 'reregister_taxonomy_pro_tags', 9999);
Thanks for the above answer saved me a ton of research but you should replace
$tax['labels']['parent_item'] = sprintf(__("Parent %s"), $tax->labels->singular_name); $tax['labels']['parent_item_colon'] = sprintf(__("Parent %s:"), $tax->labels->singular_name);
to
$tax['labels']->parent_item = sprintf(__("Parent %s"),$tax['labels']->singular_name);$tax['labels']->parent_item_colon = sprintf(__("Parent %s:"),$tax['labels']->singular_name);