3
如何在Woocommerce的結賬頁面添加每個產品的簡短描述?我已經完成了大量的研究,這是我所想到的最好的。結帳時的簡短描述woocommerce wordpress
<?php
if (sizeof($woocommerce->cart->get_cart())>0) :
foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
$_product = $values['data'];
if ($_product->exists() && $values['quantity']>0) :
echo '
<tr class = "' . esc_attr(apply_filters('woocommerce_checkout_table_item_class', 'checkout_table_item', $values, $item_id)) . '">
<td class="product-name">'.$_product->get_title().$woocommerce->cart->get_item_data($values).'</td>
<td class="short_description">'.$_product->get_post_data().$woocommerce->post->get_post_excerpt($values).'</td>
<td class="product-quantity">'.$values['quantity'].'</td>
<td class="basispreis">'.$_product->get_price().$woocommerce->post->get_post_excerpt($values).'</td>
<td class="product-total">' . apply_filters('woocommerce_checkout_item_subtotal', $woocommerce->cart->get_product_subtotal($_product, $values['quantity']), $values, $item_id) . '</td>
</tr>';
endif;
endforeach;
endif;
do_action('woocommerce_cart_contents_review_order');
?>
我得到的錯誤
開捕致命錯誤:類對象WP_Post不能在被轉換爲字符串/wp-content/plugins/woocommerce/templates/checkout/form-checkout.php 這條線
<td class="short_description">'.$_product->get_post_data().$woocommerce->post->get_post_excerpt($values).'</td>
謝謝。我如何着手讓這個功能起作用。我把它放在class-wc-cart.php中,並把<?php echo add_filter('woocommerce_get_item_data','wc_checkout_description_so_15127954',10,2); ?>我想讓它出現在頁面上。那是錯的嗎?我得到的輸出爲1. – SilverNightaFall 2013-02-28 20:33:46
對不起,只需將它放在主題的'functions.php'文件中即可。事實上,沒有'回聲'。 – brasofilo 2013-02-28 22:40:35
請參閱[此答案](http://stackoverflow.com/a/27918859/383847)WooCommerce 2.2+更新。 – helgatheviking 2015-01-13 09:34:04