-1

I am working on woocommerce cart page with add_filter "woocommerce_in_cart_product_title", There I want to show price with title.

Like "Product title ($price)"

i have tried this code, but i can not get price.

add_filter( 'woocommerce_in_cart_product_title', 'cart_product_title', 20, 3);

function cart_product_title( $title, $values, $cart_item_key ) {
    global $woocommerce;

    $items = $woocommerce->cart->get_cart();
    print_r($items);
    foreach ($items as $cart_item_key => $values) {
            echo $name = $values['prodaddons'][0]['name'].' --- ';
            echo $price = $values['prodaddons'][0]['price'].'<br>';
        }
    echo 'aaaa-'.$title.'-'.$pricees;
}
geniuscapri
  • 94
  • 3
  • 12
  • When using a filter you must use `return` and not `echo`, try changing it and see if that does the trick. – Anand Shah Nov 21 '14 at 15:50
  • Yes i know, But my question was about price, i am not getting price value with in the function. – geniuscapri Nov 22 '14 at 18:30
  • The code that you've posted above is that the same code you are using? If yes, then on the last line where is `$pricees` defined? – Anand Shah Nov 23 '14 at 07:09
  • actually that is $price not $pricees. $price have products prices, but its show all cart products prices in loop. i am not able to get one product price. – geniuscapri Nov 23 '14 at 21:14

1 Answers1

3

try this :

add_filter( 'woocommerce_cart_item_name', 'cart_product_title', 20, 3);

function cart_product_title( $title, $values, $cart_item_key ) {
    return $title . ' - ' . $values[ 'line_total' ] . '€';
}

I don't know your version of woocommerce but woocommerce_in_cart_product_title is depreciated, it's why I use woocommerce_cart_item_name, so you should try both ;)

XciD
  • 2,537
  • 14
  • 40