Add custom taxonomies to product variations

By default, product variations will inherit the categories ( product_cat ) and tags ( product_tag ) from the parent product.

But what if you've added your own taxonomies to the parent product, for example, maybe you‘re using a Brands plugin and want your variations to show up when you filter by brand.

Well in v1.1.10 of Show Single Variations it became possible to add your own taxonomies to be ported over to the variations on product save.

Let's take a look at how to add the product_brand taxonomy to the taxonomies list. Currently, if I filter by the brand of "Nike" there is a single result; our parent variable product.

Firstly, add the following code to your child theme's functions.php file:

 * Add product_brand to taxonomies list for variations.
 * @param array $taxonomies
 * @return array
function iconic_add_brands_to_variations( $taxonomies ) {
	$taxonomies[] = 'product_brand';

	return $taxonomies;

add_filter( 'iconic_wssv_variation_taxonomies', 'iconic_add_brands_to_variations', 10, 1 );

We're filtering the $taxonomies array for variations and adding product_brand to the list.

With this snippet enabled, when I re-save the parent product, any brands associated to the product will also be saved to the variations.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.