Make WooCommerce product tags or product attributes hierarchical

<?php

// Make WooCommerce product tags hierarchical.

add_filter('woocommerce_taxonomy_args_product_tag', function($args) {
  $args['hierarchical'] = true;
  return $args;
});

// Make WooCommerce product attributes hierarchical.
// Replace "color" in "pa_color" with the name (slug) of your attribute. Keep "pa_" before it.

add_filter('woocommerce_taxonomy_args_pa_color', function($args) {
  $args['hierarchical'] = true;
  return $args;
});