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

时间:2015-07-21 16:34:04

标签: php wordpress woocommerce

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

我已经展示了图片&该产品的标题(感谢@helgatheviking& this thread),但我无法得到摘录。这是我的代码:

 <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>

摘录应出现在subtitle中。 我检查并尝试了以下主题中的建议: Woocommerce - description in products page Adding a product description to the woocommerce cart page

2 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:0)

有点晚了,但是总是在这里使用:

get_the_excerpt( $product->get_id() );

kat_indo的另一个解决方案可以使用,但是WooCommerce表示您永远不应直接访问产品数据。

相关问题