Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3007698
Display parent grouped product name in woocommerce order
Closed

Comments

  •  1
    Ehab started the conversation

    How could we display the main product title before the product title inside cart and order pages

  •  767
    Janilyn replied

    Hi Ehab,

    Thank you for contacting WPClever Support Forum. 

    We’ve received your ticket and assigned one of our developers to help you with that. 

    He’ll be looking into your question and responding with specific instructions as soon as possible. 

    Please stay patient as we're having very heavy workloads, it might take some time for our developers to reach back.

    Best regards.

    Janilyn T. - WPClever Support Agent

  •  1,226
    Dustin replied

    Hi Ehab,

    Please follow these steps:

    1. Update our plugin to the latest version 2.9.8

    2. Add the below custom code (How to add custom code?)

    add_filter( 'woosg_cart_item_data', 'woosg_add_cart_item_data', 99, 3 );
    function woosg_add_cart_item_data( $data, $item, $product_id ) {
        return array( 'woosg_parent_id' => $product_id );
    }
    add_filter( 'woocommerce_cart_item_name', 'woosg_cart_item_name', 10, 2 );
    add_filter( 'woocommerce_order_item_name', 'woosg_cart_item_name', 10, 2 );
    function woosg_cart_item_name( $name, $item ) {
        if ( isset( $item['woosg_parent_id'] ) && ! empty( $item['woosg_parent_id'] ) ) {
            if ( strpos( $name, '' ) !== false ) {
                $name = '<a href="' . get_permalink( $item['woosg_parent_id'] ) . '">' . get_the_title( $item['woosg_parent_id'] ) . '</a>' . apply_filters( 'woosg_name_separator', ' → ' ) . $name;
            } else {
                $name = get_the_title( $item['woosg_parent_id'] ) . apply_filters( 'woosg_name_separator', ' → ' ) . $name;
            }
        }
        return $name;
    }
    add_action( 'woocommerce_checkout_create_order_line_item', 'woosg_add_order_item_meta', 10, 3 );
    function woosg_add_order_item_meta( $item, $cart_item_key, $values ) {
        if ( isset( $values['woosg_parent_id'] ) ) {
            $item->update_meta_data( 'woosg_parent_id', $values['woosg_parent_id'] );
        }
    }
    add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'woosg_order_item_get_formatted_meta_data', 10, 1 );
    function woosg_order_item_get_formatted_meta_data( $formatted_meta ) {
        foreach ( $formatted_meta as $key => $meta ) {
            if ( $meta->key === 'woosg_parent_id' ) {
                unset( $formatted_meta[ $key ] );
            }
        }
        return $formatted_meta;
    }
    add_action( 'woocommerce_before_order_itemmeta', 'woosg_before_order_item_meta', 10, 2 );
    function woosg_before_order_item_meta( $item_id, $item ) {
        if ( $parent_id = $item->get_meta( 'woosg_parent_id' ) ) {
            echo sprintf( esc_html__( '(in %s)', 'wpc-grouped-product' ), get_the_title( $parent_id ) );
        }
    }

    Best regards,
    Dustin

  •  1
    Ehab replied

    Hi Dustin,

    Thanks for your reply

    Our editor update the plugin to v  2.9.8 and added the code to the function file

    it's working fine on cart and checkout pages 

    but in order pages & downloads it only shows the child title without the product parent title

    is it possible to show it on these pages too

    Thanks again

    Best regards,

    Ehab