WooCommerce variation title: include attributes like size and color
A WooCommerce variation title does not always include the attributes. One product lists its variations as Hoodie - Red, XL, the next one shows Jacket on every row, in the bulk editor, in the cart and in orders, and nothing tells the options apart. That is not a broken import. WooCommerce builds every variation title itself, and it has rules for leaving the attribute values out. Below is how the title is built, the one filter that makes it include the attributes, how to see the values per variation in the bulk editor, and why a variation title cannot be typed in by hand.
How WooCommerce builds a variation title
A variation has no name field that you fill in. Each time WooCommerce saves a variation, and each time it loads one, it computes the title from two parts: the parent product's title and the variation's attribute values, joined with " - ". If the stored title differs from the computed one, for example because the parent was renamed, WooCommerce writes the new title back to the database.
The attribute values are added only when the current WooCommerce rules allow it:
- The variation has fewer than three attributes. With Color, Size and Material, the title is just the parent title.
- When there are two attributes, neither of their names may contain a hyphen. WooCommerce reads the attribute's internal name: a global attribute Shoe size with the slug
shoe-sizeis stored aspa_shoe-size, and a custom attribute typed as Sistema de activacion is stored assistema-de-activacion. Any attribute name of two or more words gets hyphens, so Color plus Shoe size gives titles without values. - A variation set to Any Size has no size value to add.
That is why two products that look identical can behave differently: one has Color and Size, the other Color and Frame size.
Make variation titles include attributes
The rules end in a filter, woocommerce_product_variation_title_include_attributes, which decides the result. Returning true from it adds the values to every variation title, whatever the number or names of the attributes:
/*
* Always add the attribute values to variation titles: "Hoodie - Red, XL".
* Child theme functions.php or a code snippets plugin.
*/
add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_true' );
To keep WooCommerce's default for variations with many attributes and only overrule the hyphen rule, decide by the number of attributes instead:
add_filter( 'woocommerce_product_variation_title_include_attributes', function ( $include, $product ) {
// Up to four attributes: always show their values in the title
if ( count( $product->get_attributes() ) <= 4 ) {
return true;
}
return $include;
}, 10, 2 );
Put the code into the functions.php of the active theme, and if that theme is a child theme, into the child theme's file. A parent theme's file is replaced on every theme update, so the Code Snippets plugin is the safer place when you do not maintain a child theme. When you copy code from a translated web page, check the punctuation: browser translation turns commas and semicolons into characters PHP does not accept.
The separator between the parent title and the values has its own filter, woocommerce_product_variation_title_attributes_separator:
add_filter( 'woocommerce_product_variation_title_attributes_separator', function () {
return ' / '; // Hoodie / Red, XL
} );
Existing variations pick it up when they are loaded
The filter changes the rule, not the titles already stored. WooCommerce compares and rewrites a variation's title the next time it loads or saves that variation: when the product is opened in the WooCommerce editor, when its product page shows the variation options, or when the variations are shown in BEAR. Nothing has to be deleted and re-created. Orders keep the name the item had when it was bought, so past orders do not change.
When the values are part of the title, WooCommerce stops repeating them under the item name in the cart, checkout and order emails, because it skips attributes that already appear in the name.
Variation titles in the bulk editor
With the variations switch on the tools panel turned on, BEAR shows every variation under its parent and builds the title of each row the same way WooCommerce does, with the attribute names in brackets at the end: Hoodie - Red, XL [color, size]. It adds the values for up to nine attributes instead of two, so in the editor you can see values where the stored title has none. The hyphen rule and the filter above apply in BEAR too, so a variation row that shows only the parent title has the same cause, and the same fix, as the cart.
The Title cell of a variation row cannot be edited, and while the variations switch is on the Bulk Edit tab hides the title operation. There is nothing to save: any title written to a variation would be replaced by the computed one the next time WooCommerce loads it. Edit the parent title instead; every variation follows it.
See the attribute value of each variation in its own column
When several attributes make the title long, show the attributes as columns. Open the Settings tab, type the attribute name into the columns finder ... field (or press Show all columns), switch the attribute on and press Save all settings. Attribute columns exist for global attributes, the ones created under Products → Attributes.
On the parent row the cell shows and edits the terms the product has. On a variation row the cell shows the red no-entry icon followed by the variation's own value, for example [XL], so you can read the value and change the price in the same row. Why that cell is not editable is explained in fields blocked on variable products and variations. To change the value a variation is built on, use the Swap or Attaching operation of Variations Advanced Bulk Operations, as shown in swapping one attribute term for another.
Renaming or translating variation names
Because the title is computed, it is renamed through its parts:
- The product part: change the parent title, in the table or with a bulk edit of the parent products. The variations follow.
- The value part: rename the term once in Products → Attributes → Configure terms. Every variation built on it shows the new name, and every product page too. Values of custom (local) attributes are plain text stored inside each product; they can only be changed product by product, which is one of the reasons to convert custom attributes to global ones.
- The whole format: the
woocommerce_product_variation_titlefilter receives the computed title, the product, the base title and the suffix, and can return any text built from them. - Translations: a multilingual plugin translates the parent title and the attribute terms, and WooCommerce builds the translated variation titles from them. Creating translated copies of products is not something BEAR does.
Some themes and plugins add their own "variation title" or "variation name" field and show it on the product page instead of the WooCommerce title. Such a field is a meta field of the variation. If you know its meta key, attach it in the Meta Fields tab and it becomes an ordinary editable column on the variation rows.
If the attributes still do not show
- Check that the snippet runs: a typo stops it silently, and code in an inactive theme does not run at all. A temporary
error_log()line inside the function shows whether it is called. - Open one affected variation in WooCommerce and confirm that each attribute has a value, not Any ….
- Reload the editor page; the titles are computed when the rows are loaded.
- A plugin that changes product names (feeds, translations, custom titles) may hook
woocommerce_product_variation_titlelater and overwrite the result. Test with that plugin switched off.
The short answer to the same question is also in the FAQ on attributes visible in one product's variations and not in another's. For a case that none of this explains, ask on the BEAR support forum.