I am developing a booking system in which the client wants only to take a USD 50 deposit and to negotiate the remaining amount separately. In order to achieve this I have used the following code to update the total price to USD 50 and to show the remaining price.
function prefix_add_discount_line( $cart ) {
$deposit = 50;
$remaining = $cart->subtotal - 50;
$cart->add_fee( __( 'Amount Remaining', 'remaining' ) , -$remaining);
}
add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line' );
In the order emails the remaining amount is displayed with a minus(-) symbol. Please let me know how to remove the minus symbol in the woocommerce order emails
To make all negative fees amounts to be displayed as a positive amount on WooCommerce Orders totals rows, use the following:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_line_html', 10, 3 );
function custom_order_total_line_html( $total_rows, $order, $tax_display ){
// Loop through WooCommerce orders total rows
foreach ( $total_rows as $key_row => $row_values ) {
// Target only "fee" rows
if ( strpos($key_row, 'fee_') !== false ) {
$total_rows[$key_row]['value'] = str_replace('-', '', $row_values['value']);
}
}
return $total_rows;
}
Now to make that only for WooCommerce email notifications, use instead this:
add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_line_html', 10, 3 );
function custom_order_total_line_html( $total_rows, $order, $tax_display ){
// Only on emails
if ( ! is_wc_endpoint_url() ) {
// Loop through WooCommerce orders total rows
foreach ( $total_rows as $key_row => $row_values ) {
// Target only "fee" rows
if ( strpos($key_row, 'fee_') !== false ) {
$total_rows[$key_row]['value'] = str_replace('-', '', $row_values['value']);
}
}
}
return $total_rows;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.