Woocommerce - 在订单页面中显示产品摘录

kat*_*ndo 1 php wordpress woocommerce

我需要在“订单”页面中显示产品的摘录。我花了几个小时试图找到解决方案,但一无所获。

我已经展示了产品的图片和标题(感谢@helgatheviking 和这个线程),但我无法显示摘录。这是我的代码:

 <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>
Run Code Online (Sandbox Code Playgroud)

摘录应出现在subtitle. 我已经检查并尝试了这些线程中的建议: Woocommerce - 产品页面中 的描述将产品描述添加到 woocommerce 购物车页面

Joh*_*ord 7

这应该这样做。the_excerpt只能与 with 结合使用,the_post()因为它取决于全局$post对象。但这几乎重新组合了它内部发生的事情。

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