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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化