← Back to Tickets
🔒 This ticket is closed.
Open New Ticket
bob
replied
Sep 5, 2026 · 2:49 am
I had Gemini write this code to do what I wanted ...
/**
* Remove parent product name but leave all attribute names for variations.
* Works across WooCommerce Cart, Checkout, Catalog, and WPC Composite Products.
*/
// 1. Target Core WooCommerce (Cart, Checkout, and Shop Catalog)
add_filter( 'woocommerce_product_variation_get_name', 'custom_variation_only_attributes', 10, 2 );
function custom_variation_only_attributes( $name, $product ) {
// Only modify on the front-end layout blocks
if ( ! is_admin() ) {
$formatted_attributes = array();
$attributes = $product->get_variation_attributes();
foreach ( $attributes as $key => $value ) {
if ( ! empty( $value ) ) {
// Remove the "attribute_" prefix to get the clean taxonomy name
$taxonomy = str_replace( 'attribute_', '', $key );
$term = get_term_by( 'slug', $value, $taxonomy );
if ( $term && ! is_wp_error( $term ) ) {
// Global attribute: fetch the proper display name (e.g., "Cotton" instead of "cotton")
$formatted_attributes[] = $term->name;
} else {
// Custom product attribute fallback: format text beautifully
$formatted_attributes[] = ucwords( str_replace( '-', ' ', $value ) );
}
}
}
// If variation attributes are found, return them joined together
if ( ! empty( $formatted_attributes ) ) {
return implode( ', ', $formatted_attributes );
}
}
return $name;
}
// 2. Target WPC Composite Products configuration elements explicitly
add_filter( 'wooco_component_product_title', 'wpc_strip_parent_keep_attributes', 10, 3 );
function wpc_strip_parent_keep_attributes( $title, $product, $component ) {
// Check if the individual component is a variation type
if ( $product && $product->is_type( 'variation' ) ) {
// Forces WPC to inherit our filtered, clean attribute string generated above
return $product->get_name();
}
return $title;
}
📎 Attachments (1):
bob started the conversation
Sep 5, 2026 · 2:09 am
Is it possible to modify how each component name gets displayed? We group our selections by product, so having the product name show in the selector is redundant and makes the options harder to read. See attached screenshot.
It'd be awesome if we could build a short-code style format for the names like [name] - [color], [size] -- then we could just make it [color] - [size].
📎 Attachments (1):




