从显示的 Woocommerce 负费用中删除减号

Remove minus sign from Woocommerce negative fees displayed amount

我正在开发一个预订系统,其中客户只想收取 50 美元的押金并单独协商剩余金额。为了实现这一点,我使用以下代码将总价更新为 50 美元并显示剩余价格。

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' ); 

在订单邮件中,剩余金额以减号 (-) 显示。请让我知道如何删除 woocommerce 订单电子邮件中的减号

要使所有 负费用金额 在 WooCommerce 订单总计行中显示为 正金额,请使用以下内容:

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;
}

现在只针对 WooCommerce 电子邮件通知,使用这个:

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;
}

代码进入活动子主题(或活动主题)的 functions.php 文件。已测试并有效。