Short Description in checkout woocommerce wordpress

How do you add a short description for each product to the checkout page in Woocommerce? I have done tons of research and this is the best I have come up with.

<?php
if (sizeof($woocommerce->cart->get_cart())>0) :
    foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
        $_product = $values['data'];
    if ($_product->exists() && $values['quantity']>0) :
        echo '
    <tr class = "' . esc_attr(apply_filters('woocommerce_checkout_table_item_class', 'checkout_table_item', $values, $item_id ) ) . '">
    <td class="product-name">'.$_product->get_title().$woocommerce->cart->get_item_data( $values ).'</td>
    <td class="short_description">'.$_product->get_post_data().$woocommerce->post->get_post_excerpt( $values ).'</td>

    <td class="product-quantity">'.$values['quantity'].'</td>

    <td class="basispreis">'.$_product->get_price().$woocommerce->post->get_post_excerpt( $values ).'</td>

    <td class="product-total">' . apply_filters( 'woocommerce_checkout_item_subtotal', $woocommerce->cart->get_product_subtotal( $_product, $values['quantity'] ), $values, $item_id ) . '</td>
    </tr>';
    endif;
    endforeach;
    endif;
    do_action( 'woocommerce_cart_contents_review_order' );
?>

I get the error

Read More

Catchable fatal error: Object of class WP_Post could not be converted to string in /wp-content/plugins/woocommerce/templates/checkout/form-checkout.php
at this line

 <td class="short_description">'.$_product->get_post_data().$woocommerce->post->get_post_excerpt( $values ).'</td>

Related posts

Leave a Reply

1 comment

  1. The filter woocommerce_get_item_data can be used for that.

    Like so:

    add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_so_15127954', 10, 2 );
    
    function wc_checkout_description_so_15127954( $other_data, $cart_item )
    {
        $post_data = get_post( $cart_item['product_id'] );
        $other_data[] = array( 'name' =>  $post_data->post_excerpt );
        return $other_data;
    }
    

    Note that maybe some kind of checking will be needed, e.g., make sure this filter is only called when actually viewing the Checkout page, as I don’t know if it’ll be called in other instances.