How to Customize Product Variation Titles via Filters

This guide will show you how to change your product variation titles using the following filters :

  • iconic_wssv_variation_attributes_used_in_the_title
  • iconic_wssv_variation_title_with_attributes

The filter iconic_wssv_variation_attributes_used_in_the_title allows customizing the attributes used in the variation title when the option Variation Title Format is set to Append variation attributes. By default, all attributes will be appended to the variation title. However, there are some cases when we would like to show only a few attributes.

For example, in the image below, the Hoodie variations use color and size attributes.

To use only the Color attribute in the variation titles, we could use the filter iconic_wssv_variation_attributes_used_in_the_title to remove the Size attribute like so:

add_filter(
	'iconic_wssv_variation_attributes_used_in_the_title',
	function( $variation_attributes, $variation_id ) {
		if ( isset( $variation_attributes['attribute_pa_size'] ) ) {
			unset( $variation_attributes['attribute_pa_size'] );
		}

		return $variation_attributes;
	},
	10,
	2
);

After adding this code snippet, the result will be:

The filter iconic_wssv_variation_title_with_attributes allows customizing the title after all attributes are appended. For example, the final result of the variation title is Hoodie – Red, Large. However, you might like to add the text ‘(variation)’ to the end of the title: ‘Hoodie – Red, Large (variation)’.

To achieve this, you can use the code snippet below:

add_filter(
	'iconic_wssv_variation_title_with_attributes',
	function( $title_with_attributes, $variation_id ) {
		return $title_with_attributes . ' (variation)';
	},
	10,
	2
);

The result would look something like this:

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.