简体   繁体   中英

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!

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.

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

终于找到了一个有效的解决方案问题解决了,将其添加到子主题 function.php 中:

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM