2015-07-21 172 views
0

我需要在訂單頁面中顯示產品摘要。我花了幾個小時試圖找到一個解決方案,但沒有。Woocommerce - 在訂單頁面中顯示產品摘錄頁面

我已經顯示出圖像&標題的產品(感謝@helgatheviking &這個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

+1

總是值得考慮看看WooCommerce本身如何爲[顯示數據](https://github.com/woothemes/woocommerce/blob/master/templates/single-product/short-description.php#L22 )。而對於字幕,請看看[我寫的插件](https://wordpress.org/plugins/kia-subtitle/) – helgatheviking

回答

3

這應該這樣做。 the_excerpt只能與the_post()組合使用,因爲它取決於全局$post對象。但是這非常重新組裝它裏面發生的事情。

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

就是這樣!十分感謝! –

+0

也'get_the_excerpt($ product-> id);'應該這樣做。 – helgatheviking

+0

對不起沒有。它不需要任何參數,即「get_the_content()」和「get_the_title()」。檢查https://codex.wordpress.org/Function_Reference/get_the_excerpt –

相關問題