问题
I'm creating my new website with Wordpress and Woocommerce. I would like to display the short description in the order detail.
I found this code :
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_single_excerpt', 5);
But that shows me the description in home.
Is there a way to make it appear in the order detail?
回答1:
It can be done with a custom unction hooked in woocommerce_order_item_name
filter hook, this way:
add_filter( 'woocommerce_order_item_name', 'add_single_excerpt_to_order_item', 10, 3 );
function add_single_excerpt_to_order_item( $item_name, $item, $is_visible ){
$product_id = $item->get_product_id(); // Get the product Id
$excerpt = get_the_excerpt( $product_id ); // Get the short description
return $item_name . '<br><p class="item-description">' . $excerpt ; '</p>';
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works. It will display the short description in Order items below the item name.
来源:https://stackoverflow.com/questions/47908299/woocommerce-short-description-in-details-order