For Woocommerce grouped products I am displaying parent product name in cart and checkout pages using the code bellow:
// Adding the grouped product ID custom hidden field data in Cart object
add_action( 'woocommerce_add_cart_item_data', 'save_custom_fields_data_to_cart', 10, 2 );
function save_custom_fields_data_to_cart( $cart_item_data, $product_id ) {
if( ! empty( $_REQUEST['add-to-cart'] ) && $product_id != $_REQUEST['add-to-cart'] ) {
$cart_item_data['custom_data']['grouped_product_id'] = $_REQUEST['add-to-cart'];
$data['grouped_product_id'] = $_REQUEST['add-to-cart'];
// below statement make sure every add to cart action as unique line item
$cart_item_data['custom_data']['unique_key'] = md5( microtime().rand() );
WC()->session->set( 'custom_data', $data );
}
return $cart_item_data;
}
// Add the parent grouped product name to cart items names
add_filter( 'woocommerce_cart_item_name', 'custom_product_title_name', 10, 3 );
function custom_product_title_name( $cart_item_name, $cart_item, $cart_item_key ){
// Only in cart and checkout pages
if ( is_cart() || is_checkout() )
{
// The product object from cart item
$product = $cart_item['data'];
$product_permalink = $product->is_visible() ? $product->get_permalink( $cart_item ) : '';
// The parent product name and data
if( ! empty( $cart_item['custom_data']['grouped_product_id'] ) ){
$group_prod_id = $cart_item['custom_data']['grouped_product_id'];
$group_prod = wc_get_product($group_prod_id);
if ( ! $group_prod->is_type( 'grouped' ) ) return $cart_item_name;
$parent_product_name = $group_prod->get_name();
$group_prod_permalink = $group_prod->is_visible() ? $group_prod->get_permalink() : '';
if ( ! $product_permalink )
return $parent_product_name . ' > ' . $product->get_name();
else
return sprintf( '<a href="%s">%s</a> > <a href="%s">%s</a>', esc_url( $group_prod_permalink ), $parent_product_name, esc_url( $product_permalink ), $product->get_name() );
}
else
return $cart_item_name;
}
else
return $cart_item_name;
}
Code comes from here: Add the parent product name to each cart item names in WooCommerce
Now I would like to display also this parent product name in orders details and in back-end too.
I will be grateful for any help on this.
I have revisited the original code answer a bit and I have enabled the display of those parent products linked names on orders and email notifications:
Code goes in function.php file of your active child theme (or theme);
Tested and works.