Woocommerce product attributes with hierarchy like categories

Viewed 2903

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...

2 Answers

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

function so44271444_woocommerce_taxonomy_args_pa_color ($data)
{
    $data['hierarchical'] = true;

    return $data;
}

add_filter('woocommerce_taxonomy_args_pa_color', 'so44271444_woocommerce_taxonomy_args_pa_color');

where pa_color is your attribute taxonomy name.

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.

Related