'Woocommerce product attributes with hierarchy like categories

Faced the task of making a filter based on the attributes of the product. I need to make a hierarchy of attributes like the product categories. Can this be realized? Maybe someone did or knows ready-made solutions, plug-ins, etc.? Tell me please...



Solution 1:[1]

You can change that using filters in your theme's functions.php file

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

where 'pa_color' is your attribute taxonomy name.

Solution 2:[2]

This is an old question, but I came across it because I was not able to add hierarchies in attributes anymore. It seems as if in newer versions of Woocommerce, the hierarchise in attributes have been removed. You can manually add them back in the code (tested and working on Woocommerce v3.8.1)

Edit /wp-content/plugins/woocommerce/includes/class-wc-post-types.php line 214

change:

'hierarchical' => false,

to:

'hierarchical' => true,

Hierarchies will now be enabled. Obviously, any time Woocommerce is upgraded, this will revert to no longer having hierarchies. I am sure there is a function that can be written but this has been the quickest way for me to get this working for now.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 O Genthe
Solution 2 O Genthe