3

我正在开发一个预订系统,其中客户只想收取 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 订单电子邮件中的减号

在此处输入图像描述

4

1 回答 1

2

要使所有负费用金额在 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 文件中。测试和工作。

于 2020-12-26T23:30:27.410 回答