Reputation: 29
In my woocommerce store I have activated the payments instructions and they are displayed on all email notifications. I have the following code (taken from another answer), that remove payment instructions for "COD" payment method:
add_action( 'woocommerce_email_before_order_table', function(){
if ( ! class_exists( 'WC_Payment_Gateways' ) ) return;
$gateways = WC_Payment_Gateways::instance(); // gateway instance
$available_gateways = $gateways->get_available_payment_gateways();
if ( isset( $available_gateways['cod'] ) )
remove_action( 'woocommerce_email_before_order_table', array( $available_gateways['cod'], 'email_instructions' ), 10, 3 );
}, 1 );
It is applied globally on all email notifications and I need to remove the payment instructions only from "Customer completed order" email notification.
Any help is appreciated.
Upvotes: 1
Views: 1684
Reputation: 253867
Your code is a bit outdated (or old) and you missed the hook function arguments, that will allow you to target "Customer Completed Order" Email notification. Try instead the following:
add_action( 'woocommerce_email_before_order_table', 'action_email_before_order_table_callback', 9, 4 );
function action_email_before_order_table_callback( $order, $sent_to_admin, $plain_text, $email ){
$payment_method = $order->get_payment_method();
// Targeting "COD" payment method on Customer completed order email notification
if ( 'customer_completed_order' === $email->id && 'cod' === $payment_method ) {
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
remove_action( 'woocommerce_email_before_order_table', [ $available_gateways[$payment_method], 'email_instructions' ], 10 );
}
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Upvotes: 3