I Would like to display the parent product name with child product name (cart item) in cart page, for my grouped products. I am selecting Parent product data as grouped product under linked product -> Grouped products adding child product.
The code from template cart.php
:
echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key )
This is what I would like for each cart item:
Parent Product > Child Product
UPDATED on 2018-02
The way is to include the grouped product id in cart object when a product is added to cart using a custom function hooked in
woocommerce_add_cart_item_data
action hook (only grouped product id will be added as custom data in cart object).Then to display the parent grouped product name with the current cart item name we use another custom function hooked in
woocommerce_cart_item_name
filter hook.See this update: Display parent grouped product name in Woocommerce orders details
So the final code is:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works for WooCommerce version 3+
You will get this: