Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove payment method from WooCommerce order confirmation email?

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> 
like image 945
emmbla Avatar asked Oct 15 '22 22:10

emmbla


1 Answers

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.

like image 84
LoicTheAztec Avatar answered Oct 18 '22 21:10

LoicTheAztec