2

I am trying to display the product variation description in the order detail page and in the order email. Following this example Woocommerce: Display Product Variation Description on Cart page it worked perfectly for the cart and also for the checkout. But it seems i can't find the right way of calling it for the order page.

This

$item = $cart_item['data'];
if(!empty($item) && $item->is_type( 'variation' ) ){
    echo '<dl><dd>' . $item->get_variation_description() }

is not working, as it calls for the cart item data .. And the get_post_meta as suggested here WooCommerce displaying variable description after variable price is not working either.

$_variable_description = get_post_meta( $variation->id , '_variation_description', true );

I tried to place it in either the order-details-item.php and the class-wc-order-item-meta.php, and of course the email-order-details.php

Any suggestions? Thanks!

aynber
  • 22,380
  • 8
  • 50
  • 63
Heiko
  • 51
  • 1
  • 5

4 Answers4

3

I finally found a solution that worked here now showing the variation description on the order page and the order email.

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

    $_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><br>'. $_var_description ;
}

It puts the variations description right below the title, but that works for me.

Heiko
  • 51
  • 1
  • 5
1

Almost 5 years later and this still works and was exactly what I needed for a bakery site I'm building.

I used this combo (in case anyone else comes along):

function display_product_title_as_link( $item_name, $item ) {

    $_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><br>'. $_var_description ;
}

add_filter( 'woocommerce_product_variation_title_include_attributes','__return_false' );

I really appreciate being able to find answers here.

  • where did you placed the code? In the functions.php or in the order-details email? It doesn't work for me – p_e_88 Feb 07 '22 at 12:36
0
add_filter( 'woocommerce_order_item_name', 'display_product_description', 10, 2 );
    function display_product_description( $item_name, $item ) {

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


        $_var_description ='';

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

        return $_var_description ;
    }

Try this in you theme's functions.php

mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • It works, as it now displays the variation description on the order page and email. BUT now it displays the description instead the name of the product .. – Heiko Feb 27 '17 at 07:48
0

Finally found a solution that worked Problem solved, add this to child theme function.php:

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
Usama Ashraf
  • 23
  • 1
  • 7