我使用了我在此处找到的 brasofilo 提供的解决方案结账 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>
编辑:
我还不能在这里上传图片,因为我是新人,所以我将问题的屏幕截图上传到
产品简短描述没有冒号。
编辑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 左右,结帐类中的
$other_data
变量已更改为需要 name
和 value
对的数组。因此,来自其他线程的代码已过时。使用它时,WooCommerce 找不到 name
或 value
,因此这些部分是空白的,您在它们应该在的位置之间只剩下冒号。尝试此更新:
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;
}
9年过去了,这仍然是一个非常需要的东西!
除了输出之前的“描述:”之外,一切正常。我们怎样才能删除这个?
感谢您的帮助!