Reputation: 1
I'm currently using the porto theme on wordpress with woocommerce, and it doesn't have an option to show the product description in the mini cart or checkout page. I was able to find the following css code to add that worked, but I'm trying to limit this to display the product descriptions for most products while excluding only items from one specific category slug.
For example, we have cart items and would like the description to be hidden only for the pats in that one category 'carts'. Here's the code I found that blanket worked for every product.
add_filter( 'woocommerce_get_item_data', 'customizing_cart_item_data', 10, 2 );
function customizing_cart_item_data( $cart_data, $cart_item ) {
$description = $cart_item['data']->get_description(); // Get the product description
// For product variations when description is empty
if( $cart_item['variation_id'] > 0 && empty( $description ) ){
// Get the parent variable product object
$parent_product = wc_get_product( $cart_item['product_id'] );
// Get the variable product description
$description = $parent_product->get_description();
}
// If product or variation description exists we display it
if( ! empty( $description ) ){
$cart_data[] = array(
'key' => __( 'Description', 'woocommerce' ),
'value' => $description,
'display' => $description,
);
}
return $cart_data;
}
Does anyone have a recommendation? Thanks in advance I really appreciate it!
Upvotes: 0
Views: 238
Reputation: 1042
Possibly just insert the following in the function before processing anything else:
if ( has_term( 'your-slug', 'product_cat', $cart_item ) ) {
return $cart_data ;
}
See https://developer.wordpress.org/reference/functions/has_term/
Upvotes: 0