Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
713 views
in Technique[技术] by (71.8m points)

php - Woocommerce: Display Product Variation Description on order page

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...