skip to Main Content

I would like to have the respective short description of the product / article displayed in WOOCOMMERCE in the order overview “Order-Details-Item” (template / woocommerce / order / order-details-item.php) about the product Permalink.

I found the following code on the web to allow a brief description.
Here is the code for this:

<div class="product_short_description_cart_default">
	<?php
	$product_id = $_product->get_parent_id();
	$product = wc_get_product($product_id);
    echo $product->get_short_description();
	?>
	</div>

But how do I incorporate them into my order-details-item.php file?
Here is the code for this:

<?php
/**
 * Order Item Details
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/order/order-details-item.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates
 * @version 3.7.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
	return;
}
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'woocommerce-table__line-item order_item', $item, $order ) ); ?>">

	<td class="woocommerce-table__product-name product-name">
		<div class="order-details-item-default-product-name-left">
		<?php
		echo '<div class="product-image">'.$product->get_image(array( 80, 80)).'</div>';
		$is_visible        = $product && $product->is_visible();
		$product_permalink = apply_filters( 'woocommerce_order_item_permalink', $is_visible ? $product->get_permalink( $item ) : '', $item, $order );
		?>
		</div>
		<div class="order-details-item-default-product-name-right">
		<?php
		echo apply_filters( 'woocommerce_order_item_name', $product_permalink ? sprintf( '<a href="%s">%s</a>', $product_permalink, $item->get_name() ) : $item->get_name(), $item, $is_visible ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

		$qty          = $item->get_quantity();
		$refunded_qty = $order->get_qty_refunded_for_item( $item_id );

		if ( $refunded_qty ) {
			$qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * -1 ) ) . '</ins>';
		} else {
			$qty_display = esc_html( $qty );
		}

		echo apply_filters( 'woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf( '&times; %s', $qty_display ) . '</strong>', $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

		do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, false );

		wc_display_item_meta( $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

		do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, false );
		
		// SKU mit Sprachdatei										
		echo '<div class="cart-sku-item">' . __( "SKU:", "woostroid") . $product->sku . '</div>';
		
		?>
		</div>
	</td>

	<td class="woocommerce-table__product-total product-total">
		<?php echo $order->get_formatted_line_subtotal( $item ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
	</td>

</tr>

<?php if ( $show_purchase_note && $purchase_note ) : ?>

<tr class="woocommerce-table__product-purchase-note product-purchase-note">

	<td colspan="2"><?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>

</tr>

<?php endif; ?>

Can you please help me there!

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for your efforts and for the great code.

    But did we talk past each other ?!

    So I would like to have the following displayed next to the product image:

    1. Product short description
    2. Product name with link
    3. Design / (variants of products)
    4. Item number (SKU NUMBER)

    points 2 and 3 and 4 work.

    I only miss the first point (product short description) (echo $ product-> get_short_description ();)

    Excuse me for my first bad description.


  2. Just place below code in functions.php

    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'] );
    
    
            $_var_description ='';
    
            if ( $item['variation_id'] ) {
                $_var_description = $_product->get_variation_description();
            }else{
                $_var_description = $_product->get_short_description();
            } 
    
            return $_var_description.'<br>'.$item_name;
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search