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. In the below example, if I filter by the brand of “Nike” there’s a single result; our parent variable product. Let’s change that.

example of product brand on display

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 you re-save the parent product, any brands associated with the product will also be saved to the variations.

shop example with multiple products with brands

WooCommerce Show Single Variations

Display individual product variations of a variable product in your product listings. Make it easy for your customers to view and filter product variations.

Was this helpful?

Please let us know if this article was useful. It is the best way to ensure our documentation is as helpful as possible.