-1

I want to add additional cost in the cart product total price, not in product price nor the whole cart total price. I am referring about the product total price.

Right now i have not not try and I don't have any code.

add_action( 'woocommerce_before_calculate_totals', 'function add_additional_price' );
function add_additional_price( $cart_object ) {
    $custom_price = 10; // This will be your custome price  
}
ham-sandwich
  • 3,975
  • 10
  • 34
  • 46
geniuscapri
  • 94
  • 3
  • 12

1 Answers1

3

You can try this

// Change the line total price
add_filter( 'woocommerce_get_discounted_price', 'calculate_discounted_price', 10, 2 );
// Display the line total price
add_filter( 'woocommerce_cart_item_subtotal', 'display_discounted_price', 10, 2 );

function calculate_discounted_price( $price, $values ) {
    // You have all your data on $values;
    $price += 10;
    return $price;
}

// wc_price => format the price with your own currency
function display_discounted_price( $values, $item ) {
    return wc_price( $item[ 'line_total' ] );
}
XciD
  • 2,537
  • 14
  • 40
  • code is not working, i think functions are not calling in hook. can you explain a bit more? – geniuscapri Nov 25 '14 at 22:57
  • Yes, i Forgot to change function name – XciD Nov 25 '14 at 23:21
  • Thanks for answer, its also working. But getting a problem from previous answer. "Show price with product title." that was also working, but total price showing with title and i want to show actual product price. Please help. This is previous question link: http://stackoverflow.com/questions/27035312/how-can-i-get-price-in-woocommerce-cart-product-title-hook/27068018 – geniuscapri Nov 27 '14 at 18:50
  • If I undertand right : you need to display the right price on the title and the discount price on price column ? – XciD Nov 27 '14 at 20:48
  • No, i just want to show actual product price with title. with out adding additional cost. like showing in price column, not total column price. – geniuscapri Nov 28 '14 at 21:03