duanjie6912 2015-01-12 10:37
浏览 20
已采纳

解决方案简短说明结帐woocommerce wordpress不适合我

I have used the Solution provided by brasofilo i found here Short Description in checkout woocommerce wordpress.

But for some reason, a colon gets added after every Description of every Product.

I used firebug to try to find out where that may come from. It shows up at the end of the dt class="variation-Productdescription" of every Product shown on the checkoutpage. Here is the code I copied from 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>

Edit:

I can't upload images here yet as I am new, so I uploaded a screenshot of the problem to http://i.imgur.com/HMh8A3P.jpg?1

The Product Short Description doesn't have the colon.

A Screenshot of the Product Short Description

Edit 2:

A solution that is working for me right now is:

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

But as helgatheviking has pointed out, this is not a good solution, even though it works.

I will work on a better solution without the echo.

  • 写回答

1条回答 默认 最新

  • douti9286 2015-01-13 09:33
    关注

    I think sometime around WooCommerce v2.2 the $other_data variable in the checkout class was changed to an array requring name and value pairs. As such, the code from the other thread is outdated. Using it WooCommerce can't find the name or the value so those parts are blank and you are left with only the colon in between where they should be. Try this update:

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程