I'm struggling to modify the cart page in woocommerce. I have the cart.php
file in my theme folder, and I want to add some information about the products in that page.
I want to add two hooks:
woocommerce_template_single_excerpt
woocommerce_template_single_meta
But I'm not sure how to do it. I'm trying to add those hooks in some versions of the next basic code:
add_action( 'woocommerce_before_cart_contents','matusevitch_cart_page_info' );
function matusevitch_cart_page_info(){
// Your code
}
now in the function I tried either just to echo the hook, or to add it like this:
do_action( 'woocommerce_before_cart_contents','woocommerce_template_single_meta' );
I tried as well some solutions in other threads I checked before, but non of this works.
How can I display product excerpt for items on cart page?
This can simply be done this way for example:
add_filter( 'woocommerce_cart_item_name', 'add_excerpt_in_cart_item_name', 10, 3 );
function add_excerpt_in_cart_item_name( $item_name, $cart_item, $cart_item_key ){
$excerpt = wp_strip_all_tags( get_the_excerpt($cart_item['product_id']), true );
$style = ' style="font-size:14px; line-height:normal;"';
$excerpt_html = '<br>
<p name="short-description"'.$style.'>'.$excerpt.'</p>';
return $item_name . $excerpt_html;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works