Solution for Short Description in checkout woocomm

2019-02-21 01:23发布

问题:

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:

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