0
votes

I want to remove the Subtotals from Cart, Checkout, Order Received, Order Details and the emails. I don't want to use CSS, as it won't remove the reference from the order details page and emails. I have tried this code:

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

It isn't working, the Subtotal is visible on the Cart and Checkout pages.

Is there any other function or do I have to create a separate woocommerce folder under my active theme and delete any reference of "Subtotal" from the templates.

1

1 Answers

9
votes

1) For All orders pages and email notifications (Order received, Order pay, Order view and emails)

Your code works and remove the subtotal line from totals lines:

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

Code goes in function.php file of your active child theme (active theme). Tested and works.

enter image description here

2) For cart and checkout pages:

You need to create a separate "woocommerce" folder under your active theme for the following templates:

For cart - cart/cart-totals.php | remove the code block from line 32 to 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>

For checkout - checkout/review-order.php | remove the code block from line 58 to 61:

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

Save both templates… You are done.