2
votes

I'm trying to display product description and variation description:

1. In the order received page and emails

I'm using Woocommerce: Display Product Variation Description on order page answer code.

This code works for v5.3 but now product quantity moved at the end of the decription -> https://prnt.sc/12yc7l4.

This is my attempt to solve the problem.

add_filter( 'woocommerce_order_item_name', 'display_product_title_as_link', 10, 3 );
function display_product_title_as_link( $item_name, $item ,$qty) {

    $_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );

    $link = get_permalink( $_product->id );

    $_var_description ='';

    if ( $item['variation_id'] ) {
        $_var_description = $_product->get_variation_description();
    }

    return '<a href="'. $link .'"  rel="nofollow">'. $item_name .'</a>'. $qty .'<br>'. $_var_description ;
}

How can I apply this so that it has no influence between the product name and the product quantity?


2. in cart, mini cart and checkout page - i'm using WooCommerce: Display also product variation description on cart items answer code

Using this lines works for v5.3 but now the description completely replaces the product name while it would be useful if the product description were added to the product name. How can I fix it?

EDIT: issue 2 is fixed!

1
The 2nd link to which you are referring contained a small error, I have corrected that answer7uc1f3r
Thank you @7uc1f3r. It works. I'm trying to solve myself the 1st one but still can't solve it. This is my codeuser15929214

1 Answers

1
votes

To display the $decription on a new line, you can use the woocommerce_order_item_meta_start action hook versus woocommerce_order_item_name filter hook.

So you get:

function action_woocommerce_order_item_meta_start( $item_id, $item, $order, $plain_text ) {
    // Get product
    $product = $item->get_product();

    // Variation description
    if ( $item['variation_id'] > 0 ) {
        $description = $product->get_description();
    } else {
        // Product short description (for others)
        $description = $product->get_short_description();
    }
    
    echo '<div>' . $description . '</div>';
}
add_action( 'woocommerce_order_item_meta_start', 'action_woocommerce_order_item_meta_start', 10, 4 );