0

We are using Woocommerce Payments and on our order confirmation email the payment method comes up as Woocommerce Payments instead of the payment source such as Visa, Mastercard etc.

enter image description here

I have found how to remove the Payment method altogether (see below), but how would I remove this and add back in Payment Source?

<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
            }
        }
    }
?>
  • I don't think there's a hook to change the payment source or to add something into the table. But there are hooks that would allow you to insert information before or after the table. This [visual guide](https://www.businessbloomer.com/woocommerce-visual-hook-guide-emails/) may be helpful. – Dave S Nov 08 '21 at 03:19
  • This is so helpful Dave! Thank you. – Marney Fontana Nov 08 '21 at 06:18
  • @MarneyFontana There does exist a hook to add/remove something to/from the table without having to overwrite the template file. My question here is, isn't it more a matter of modifying the existing row instead of deleting it and add a new one? Which plugin is it specifically about? since there are many plugins with similar names – 7uc1f3r Nov 08 '21 at 14:03
  • @7uc1f3r yes I would much prefer to modify the existing row. It is not a plug-in, just the default woocommerce/emails/email-order-details.php template that I am hoping to modify. The confusion comes from when a customer sees the Order Confirmation screen after they have made a purchase, the Payment Method is started correctly as "Visa credit card", but on the email the customer receives, the Payment Method now displays Woocommerce Payments (as per screenshot above) – Marney Fontana Nov 08 '21 at 23:53
  • @MarneyFontana You can overwrite the value (as in the answer given to your question), but i believe it's better to look at where the value comes from instead of using a 'workaround'. To get that value `get_payment_method_title()` is used in WooCommerce, and this can simply be adjusted via the WooCommerce settings. Have you already viewed/adjusted that setting? It can be found via WooCommerce -> Settings -> Payments (or checkout) -> Manage the desired method -> Title – 7uc1f3r Nov 09 '21 at 08:09

2 Answers2

1

In your functions.php add this

add_filter( 'woocommerce_get_order_item_totals', 'change_payment_method_name_in_emails', 10, 3 );
function change_payment_method_name_in_emails( $total_rows, $order, $tax_display ){
    // On Email notifications only
    if ( ! is_wc_endpoint_url() ) {
        if($total_rows['payment_method']['value'] === 'Woocommerce Payments'){
            $total_rows['payment_method']['value'] = 'Visa/Master';
        }
    }
    return $total_rows;
}
Snuffy
  • 1,723
  • 1
  • 5
  • 9
0

It seems that the order field _payment_method_title is used in emails, while '_payment_method is the one displayed in the admin panel. So one option would be to update this field:

$order->update_meta_data('_payment_method_title', '(payment method');

You could do this in an action when the order is created or marked paid.

user905686
  • 4,491
  • 8
  • 39
  • 60