I am working on a theme created for woocommerce, built by some other German developer. I have created my child theme and using child theme's functions.php to make changes to functionality of the website.
When a customer orders a product, he receives an email with order table, customer information and billing address and customer shipping. I want to remove everything below the table and add my own text (customer info + billing, shipping and pick up address as well).
I have added my own text right below the order table in email that goes to customer, however I am unable to delete the information that shows by default below my custom added text. I found the hook responsible for fetching and showing that data is woocommerce_email_order_meta
, but I don't know how to remove it or prevent it from executing. I don't want to make changes in the template files, I want to do it all by hooks.
So far I have tried doing it like this:
remove_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
I followed the link: Delete order info section from email template in woocommerce and tried the following code as well, but didn't work.
function so_39251827_remove_order_details( $order, $sent_to_admin, $plain_text, $email ){
$mailer = WC()->mailer(); // get the instance of the WC_Emails class
remove_action( 'woocommerce_email_order_details', array( $mailer, 'order_details' ), 10, 4 );
}
add_action( 'woocommerce_email_order_details', 'so_39251827_remove_order_details', 5, 4 );
How can I achieve this?
Explanations - In all email notification templates you have this:
/**
* @hooked WC_Emails::customer_details() Shows customer details
* @hooked WC_Emails::email_address() Shows email address
*/
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
After some research in WooCommerce core files and some test, I have removed successfully the customer details, the billing and shipping address from notification emails as you wished.
Here is the code:
add_action( 'woocommerce_email_customer_details', 'removing_customer_details_in_emails', 5, 4 );
function removing_customer_details_in_emails( $order, $sent_to_admin, $plain_text, $email ){
$mailer = WC()->mailer();
remove_action( 'woocommerce_email_customer_details', array( $mailer, 'customer_details' ), 10 );
remove_action( 'woocommerce_email_customer_details', array( $mailer, 'email_addresses' ), 20 );
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and fully functional.
References :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With