The following hooked function will do the job (You may need to add some CSS style rules):
// Display the product thumbnail in order view pages
add_filter( 'woocommerce_order_item_name', 'display_product_image_in_order_item', 20, 3 );
function display_product_image_in_order_item( $item_name, $item, $is_visible ) {
// Targeting view order pages only
if( is_wc_endpoint_url( 'view-order' ) ) {
$product = $item->get_product(); // Get the WC_Product object (from order item)
$thumbnail = $product->get_image(array( 36, 36)); // Get the product thumbnail (from product object)
if( $product->get_image_id() > 0 )
$item_name = '<div class="item-thumbnail">' . $thumbnail . '</div>' . $item_name;
}
return $item_name;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Note the WC_Product
method get_image()
uses Wordpress get_the_post_thumbnail()
internally.
Update: added if( $product->get_image_id() > 0 )
to the code, to display the product image, only when it exist.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…