Woocommerce: show fee in cart with negative values

I have set up some functions in a theme where I add a discount with add_fee. The discount is variable and is activated based on the products that the customer has added to his cart. By default in your woo theme files it is probably "wc_cart_totals_fee_html" which prints fee value and as such it is also fine if it is + value. If it is a negative (minus value e.g. -€10) value then it does not print a minus sign in front and it therefore prints it as if it is plus value. It is only visual because it calculates it correctly and subtracts the amount from the total.

I wanted to make it visually clear that the amount is deducted, just like when activating a discount code and therefore I made this little code piece. The function should be inserted into your WP theme functions.php file and then you should access your woo theme files. Respectively cart/cart-cart-totals.php and checkout/review-order.php. Here you need to replace "wc_cart_totals_fee_html($fee) with custom_fee_pretty_with_negative($fee) and poof it writes a minus in front of your negative values in fee.

You can find the code here:

function custom_fee_pretty_with_negative($fee) {
	$feeprice = number_format( $fee->amount + $fee->tax, 2 );
	if ( $feeprice < 0 ) {
		$replace = '-' . get_woocommerce_currency_symbol();
		$feeprice = str_replace( '-', $replace, $feeprice );
	} else {
		$feeprice = wc_price( $feeprice );
	return $feeprice;