结帐 woocommerce wordpress 中简短描述的解决方案对我不起作用

Solution for Short Description in checkout woocommerce wordpress not working for me

我已经使用了我在这里找到的 brasofilo 提供的解决方案 Short Description in checkout woocommerce wordpress

但出于某种原因,每个产品的每个描述后都会添加一个冒号。

我用 firebug 试图找出它可能来自哪里。它显示在结帐页面上显示的每个产品的 dt class="variation-Productdescription" 的末尾。这是我从 firebug:

复制的代码
<tbody>
<tr class="cart_item">
<td class="product-name">
<a href="http://shopurl/product/Product1/">Product1</a>
<strong class="product-quantity">× 1</strong>
<dl class="variation">
<dt class="variation-Productdescription">
<div class="post-content">
:
</dt>
<dd class="variation-Productdescription></dd>
</dl>
</td>
<td class="product-total">
</tr>
<tr class="cart_item">
</tbody>

编辑:

由于我是新手,我还不能在这里上传图片,所以我把问题的截图上传到http://i.imgur.com/HMh8A3P.jpg?1

产品简短描述中没有冒号。

A Screenshot of the Product Short Description

编辑 2:

目前适合我的解决方案是:

 add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_so_27900033', 10, 2 ); 
function wc_checkout_description_so_27900033( $other_data, $cart_item )
{
 $post_data = get_post( $cart_item['product_id'] );
 echo $post_data->post_excerpt;
 return $other_data;
 }

但正如 helgatheviking 指出的那样,这不是一个好的解决方案,即使它有效。

我会在没有 echo 的情况下寻找更好的解决方案。

我认为在 WooCommerce v2.2 前后的某个时候,结帐 class 中的 $other_data 变量已更改为需要 namevalue 对的数组。因此,来自其他线程的代码已过时。使用它 WooCommerce 找不到 namevalue 所以这些部分是空白的,你只剩下它们应该在的地方之间的冒号。试试这个更新:

add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_so_27900033', 10, 2 );

function wc_checkout_description_so_27900033( $other_data, $cart_item )
{
    $post_data = get_post( $cart_item['product_id'] );
    $other_data[] = array( 'name' =>  'description', 'value' => $post_data->post_excerpt );
    return $other_data;
}