Add custom Taxonomies to Single Variations
If you want to add custom taxonomies to your product variations, you can use the “woocommerce_single_variations_taxonomies” filter. An example how to add the product brand taxonomy can be found here:
/**
* Add product_brand to taxonomies list for variations.
*
* @param array $taxonomies
*
* @return array
*/
add_filter( 'woocommerce_single_variations_taxonomies', 'add_custom_taxonomies', 10, 1 );
function add_custom_taxonomies( $taxonomies ) {
$taxonomies[] = 'product_brand';
return $taxonomies;
}
After you have placed this function in your child theme functions.php file. Make sure you click on “init” in plugin admin settings again.
Questions & answers (10)
StefanNovember 18, 2023
I added a custom taxonomy using JetEngine, and it seems that this solution doesn’t work with JetEngine.
Besides, is there an option/possibility to display attributes that are not used for variations? Should they also be copied to the variation? And is there maybe a possibility of displaying all the metadata assigned to a variation (for debugging)?
FileOctober 22, 2023
/**
* Add product_brand to taxonomies list for variations.
*
* @param array $taxonomies
*
* @return array
*/
add_filter( ‘woocommerce_single_variations_taxonomies’, ‘add_custom_taxonomies’, 10, 1 );
function add_custom_taxonomies( $taxonomies ) {
$taxonomies[] = ‘pwb-brand’;
return $taxonomies;
}
this works for me with perfect brands for woocommerce.
JørgenAugust 20, 2024
Hi! Does the products show in the Brand page for you? The products don show for me.. I use Perfect brands
fileOctober 22, 2023
In my case I have perfect brand for woocommerce installed, how should I put the code?
DanielOctober 22, 2023
You may ask the plugin developer what their taxonomy name is.
FileOctober 22, 2023
Thanks for the response, when you have the name of the taxonomy. Where should I replace the code?
FileOctober 22, 2023
Ok, thanks you. When I have the name of the taxonomy, how should I put it in the code?I must replace ‘product_brand’? 2 times in the code.
DanielNovember 23, 2022
The parent attributes will be inherited, except the variation attributes of course..
Haavard H.November 23, 2022
Will this make the variations inherit the parent taxonomy values, or is it possible to set unique values per variation? For example a color attribute per single variation, without using this attribute to create the variation.
clerAugust 14, 2022
Hi, when I add product variants via Shortcode no CSS styling is loaded.
Any solution to this?
Thank you