If I understand your goal correctly, I see a few problems with your code..
First is the echo
in $newprice = echo $value['line_total'] - $value['data']->get_regular_price();
Please remove the echo
.
Second, I think you are better of using the “after”, that is woocommerce_after_calculate_totals
. You are using the “before”, that is after your code runs, line_total
will be changed.