从 WooCommerce 的订单页面、电子邮件通知和购物车 + 结帐页面中删除小计行

Remove subtotal line from orders pages, email notifications and cart + checkout pages in WooCommerce

我想从购物车、结账、收到的订单、订单详情和电子邮件中删除小计。我不想使用 CSS,因为它不会从订单详细信息页面和电子邮件中删除引用。我试过这段代码:

add_filter( 'woocommerce_get_order_item_totals', 'adjust_woocommerce_get_order_item_totals' );

function adjust_woocommerce_get_order_item_totals( $totals ) {
  unset($totals['cart_subtotal']  );
  return $totals;
}

它不起作用,小计在购物车和结帐页面上可见。

是否有任何其他功能,或者我是否必须在我的活动主题下创建一个单独的 woocommerce 文件夹并从模板中删除对 "Subtotal" 的任何引用。

1) 对于所有订单页面和电子邮件通知 (收到订单、支付订单、查看订单和电子邮件)

您的代码有效并从总计行中删除小计行:

add_filter( 'woocommerce_get_order_item_totals', 'remove_subtotal_from_orders_total_lines', 100, 1 );
function remove_subtotal_from_orders_total_lines( $totals ) {
    unset($totals['cart_subtotal']  );
    return $totals;
}

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

2) 对于购物车和结帐页面:

您需要 to create a separate "woocommerce" folder under your active theme 用于以下模板:

购物车 - cart/cart-totals.php |从第 32 行到第 35 行删除代码块:

<tr class="cart-subtotal">
    <th><?php _e( 'Subtotal', 'woocommerce' ); ?></th>
    <td data-title="<?php esc_attr_e( 'Subtotal', 'woocommerce' ); ?>"><?php wc_cart_totals_subtotal_html(); ?></td>
</tr>

结帐 - checkout/review-order.php |从第 58 行到第 61 行删除代码块:

<tr class="cart-subtotal">
    <th><?php _e( 'Subtotal', 'woocommerce' ); ?></th>
    <td><?php wc_cart_totals_subtotal_html(); ?></td>
</tr>

保存两个模板……大功告成。