You can send a different individual email address for each payment method using this custom function using hook_you hook. There are many options that you can set for this, referring to the link to the wp_mail () function .
Here is the code:
add_action( 'woocommerce_thankyou', 'wc_cheque_payment_method_email_notification', 10, 1 ); function wc_cheque_payment_method_email_notification( $order_id ) { if ( ! $order_id ) return; $order = wc_get_order( $order_id ); $user_complete_name_and_email = $order->billing_first_name . ' ' . $order->billing_last_name . ' <' . $order->billing_email . '>'; $to = $user_complete_name_and_email; // ==> Complete here with the Shop name and email <== $headers = 'From: Shop Name < name@email.com >' . "\r\n"; // Sending a custom email when 'cheque' is the payment method. if ( get_post_meta($order->id, '_payment_method', true) == 'cod' ) { $subject = 'your subject'; $message = 'your message goes in here'; } // Sending a custom email when 'Cash on delivery' is the payment method. elseif ( get_post_meta($order->id, '_payment_method', true) == 'cheque' ) { $subject = 'your subject'; $message = 'your message goes in here'; } // Sending a custom email when 'Western Union' is the payment method. else { $subject = 'your subject'; $message = 'your message goes in here'; } if( $subject & $message) { wp_mail($to, $subject, $message, $headers ); } }
This code goes in the functions.php file of your active child theme (or theme), as well as in any plug-in file.
It is tested and works.
- Update - Related to your comments.
Getting available methods of paying for a bullet (temporary to get all slugs). This will display your available payment methods as a bullet on the store page or product pages. After use, simply remove it.
Here is the functional code:
function the_available_payment_gateways(){ foreach(WC()->payment_gateways->get_available_payment_gateways() as $payment_gateway) echo '<div style="border:solid 1px #999">Method Title: "'.$payment_gateway->title .'" / Method slug: "'.$payment_gateway->id .'"</div>'; } add_action( 'woocommerce_before_main_content', 'the_available_payment_gateways', 1 );
This code is in the function.php file of your active child theme (or theme). Remove it after use.
source share