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