kat_indo
kat_indo

Reputation: 422

Woocommerce - Display product excerpt in Orders page

I need to show the product's excerpt in the Orders page. I spent several hours trying to find a solution but nothing.

I already show the image & the title of the product (Thanks to @helgatheviking & this thread) , but I can't get the excerpt to show. This is my code:

 <div id="order-column" class="my_account_orders">
   <div class="wrap">
     <?php
       foreach ( $customer_orders as $customer_order ) {
       $order = wc_get_order( );
       $order->populate( $customer_order );

       foreach( $order->get_items() as $item_id => $item ) {
           $product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
           $product->get_image();
           $product->get_title();             
       }         
       $item_count = $order->get_item_count();
   ?>
    <div class="orders-wrap">
      <div class="preview">
        <div class="image">
          <div class="image-wrap"><?php echo $product->get_image(); ?></div>
        </div>

    <div class="bottom">
      <div class="details">
        <h3 class="name"><a title="View Order" href="<?php echo $order->get_view_order_url(); ?>"><?php echo $product->get_title(); ?></a></h3>
        <h4 class="subtitle"><?php the_excerpt(); ?></h4>              
      </div>
    </div>

The excerpt should appear in subtitle. I have checked and tried the suggestions in these threads: Woocommerce - description in products page Adding a product description to the woocommerce cart page

Upvotes: 1

Views: 17947

Answers (2)

user6580560
user6580560

Reputation:

A bit late but always use this here:

get_the_excerpt( $product->get_id() );

The other solution from Johan Palmfjord will work but WooCommerce says that you never should access the product data directly.

Upvotes: 5

Johan Palmfjord
Johan Palmfjord

Reputation: 681

This should do it. the_excerpt can only be used in combination with the_post() as it depends on the global $post object. But this pretty much reassembles what happens inside it.

<h4 class="subtitle"><?php echo apply_filters( 'the_excerpt', $product->post->post_excerpt ); ?></h4>

Upvotes: 7

Related Questions