I am using the 2nd code snippet from Add product description to cart items in Woocommerce answer and added it to my function.php file to display the product description in the WooCommerce cart. It works great but within my product description is a shortcode from this plugin https://wordpress.org/plugins/simple-divi-shortcode/ and it does not display in the cart correctly. The shortcode [showmodule id="261"] is displayed instead.
Asked
Active
Viewed 320 times
2
-
Is [showmodule id="261"] always in the same position in the description? Like at the begin or at the end? – Raffobaffo Jul 08 '20 at 14:59
-
1Yes, it is always in the same position at the top. @LoicTheAztec code solved the problem. Thank you. – Stuart Hingston Jul 08 '20 at 16:24
-
@StuartHingston Is better to comment in my answer comment zone if you want me to get notified. – LoicTheAztec Jul 08 '20 at 16:30
1 Answers
2
You need simply to embed the product descition in WordPress do_shortcode()
function like:
add_filter( 'woocommerce_cart_item_name', 'customizing_cart_item_data', 10, 3);
function customizing_cart_item_data( $item_name, $cart_item, $cart_item_key ) {
// The label
$label = __( 'Description', 'woocommerce' );
// Get the product description
$description = $cart_item['data']->get_description();
// For product variations when description is empty
if( $cart_item['data']->is_type('variation') && empty( $description ) ){
// Get the parent variable product object
$product = wc_get_product( $cart_item['data']->get_parent_id() );
// Get the variable product description
$description = $product->get_description();
}
if( ! empty( $description ) ){
$item_name .= '<p class="item-description" style="margin:12px 0 0;">
<strong>'.$label.'</strong>: <br>' . do_shortcode( $description ) . '
</p>';
}
return $item_name;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

LoicTheAztec
- 229,944
- 23
- 356
- 399
-
Thank you. This worked great. Is there a way to also hide the product title in the cart? I can not target it with CSS as it does not have a class so the description is also affected. – Stuart Hingston Jul 08 '20 at 18:04
-
Ok, yes I did and was unable to get it to work. I will post a new question now. Thank you. – Stuart Hingston Jul 08 '20 at 18:10
-