结帐时的简短描述解决方案 woocommerce wordpress 对我不起作用 [英] Solution for Short Description in checkout woocommerce wordpress not working for me

查看:25
本文介绍了结帐时的简短描述解决方案 woocommerce wordpress 对我不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 brasofilo 提供的解决方案,我在这里找到了 结帐 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.

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

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>

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

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.

产品简短描述的屏幕截图

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

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

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

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

I will work on a better solution without the echo.

推荐答案

我认为在 WooCommerce v2.2 的某个时候,结帐类中的 $other_data 变量已更改为需要 name 的数组value 对.因此,来自另一个线程的代码已过时.使用它 WooCommerce 无法找到 namevalue,因此这些部分是空白的,并且在它们应该位于的位置之间只剩下冒号.试试这个更新:

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

这篇关于结帐时的简短描述解决方案 woocommerce wordpress 对我不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆