How to remove payment method from WooCommerce order confirmation email?
Asked Answered
T

1

6

We've removed the payment information on our customer emails but can't remove the title. How do we do it?We're using Woocommerce email templates for order confirmation emails.

We've searched in and tried to change

  • email-order-details.php
  • email-order-items.php
  • customer-on-hold-order. php (our customer use on-hold-order as default template for confirmation emails to customers)

We tried this one in email-order-details, it did not work at all.

<tfoot>
    <?php
        if ( $totals = $order->get_order_item_totals() ) {
            $i = 0;
            foreach ( $totals as $total ) {
                $i++;
                if ( $total['label'] != 'Payment Method:' ){
                    ?><tr>
                        <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
                        <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
                    </tr><?php
                }
            }
        }
    ?>
</tfoot> 
Tripe answered 2/2, 2021 at 13:33 Comment(0)
B
5

To remove payment method from WooCommerce email notifications using hooks:

add_filter( 'woocommerce_get_order_item_totals', 'remove_paymeny_method_row_from_emails', 10, 3 );
function remove_paymeny_method_row_from_emails( $total_rows, $order, $tax_display ){
    // On Email notifications only
    if ( ! is_wc_endpoint_url() ) {
        unset($total_rows['payment_method']);
    }
    return $total_rows;
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works.


Or overriding email-order-details.php template file:

<tfoot>
    <?php
        if ( $totals = $order->get_order_item_totals() ) {
            $i = 0;
            foreach ( $totals as $key => $total ) {
                $i++;
                if ( $key !== 'payment_method' ){
                    ?><tr>
                        <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
                        <td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
                    </tr><?php
                }
            }
        }
    ?>
</tfoot> 

It should also works.

Bechuanaland answered 2/2, 2021 at 13:58 Comment(1)
Thank you for answering, we tried that, it didn't work at first. When we removed old plugin for bank transfer payments it worked fine. Thank you!Tripe

© 2022 - 2024 — McMap. All rights reserved.