I am trying to remove info above the table about order from processing order email in woocommerce. In customer-processing-order.php i found this hook:
/*
* #hooked WC_Emails::order_details() Shows the order details table.
* #hooked WC_Structured_Data::generate_order_data() Generates structured data.
* #hooked WC_Structured_Data::output_structured_data() Outputs structured data.
* #since 2.5.0
*/
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
How to remove the first hooked function from processing order email notification (to get blank order info I suppose)?
You can use the following to remove order details from WooCommerce processing email notification sent to customer:
add_action( 'woocommerce_email_order_details', 'action_email_order_details', 2, 4 );
function action_email_order_details( $order, $sent_to_admin, $plain_text, $email ) {
// Targeting "processing" order email notification sent to customer.
if ( 'customer_processing_order' === $email->id ) {
remove_action( 'woocommerce_email_order_details', array( WC()->mailer(), 'order_details' ) );
}
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Related
I'm looking for the easiest way to remove this tracking number tablefrom a transactional email in woocommerce.
Image attached to show what I mean.
I understand it's pulled from a function, but I don't know how to edit it without destroying the rest of the table, which I need to stay as is.
I'm not a coder, but I can follow instructions. Could tell me where I need to go and which parts to change. I could probably find my way into the function file, but I don't know how to edit it safely or what to delete/change.
<?php
/*
* #hooked WC_Emails::order_details() Shows the order details table.
* #hooked WC_Structured_Data::generate_order_data() Generates structured data.
* #hooked WC_Structured_Data::output_structured_data() Outputs structured data.
* #since 2.5.0
*/
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
/*
* #hooked WC_Emails::order_meta() Shows order meta data.
*/
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
/*
* #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 );
/*
* #hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
I am trying to find a way to add the Authorize.net ID (not the woocommerce customer ID) to the admin order template. The Authorize.net ID shows on the order screen:
I want that ID # to go in the email. Here is the e-mail template:
<?php
/**
* Admin new order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/admin-new-order.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates/Emails/HTML
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* #hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<p><?php printf( __( 'You have received an order from %s. The order is as follows:', 'woocommerce' ), $order->get_formatted_billing_full_name() ); ?></p>
<?php
/**
* #hooked WC_Emails::order_details() Shows the order details table.
* #hooked WC_Structured_Data::generate_order_data() Generates structured data.
* #hooked WC_Structured_Data::output_structured_data() Outputs structured data.
* #since 2.5.0
*/
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
/**
* #hooked WC_Emails::order_meta() Shows order meta data.
*/
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email, $transaction_ID );
/**
* #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 );
/**
* #hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
Any ideas? I appreciate any guidance I can get.
This code will display the transaction ID (when it exists) in Woocommerce admin email notifications:
// Display the payment gateway transwaction ID on email notifications
add_action('woocommerce_email_order_details', 'before_email_order_details_transaction_id', 5, 4 );
function before_email_order_details_transaction_id( $order, $sent_to_admin, $plain_text, $email ) {
if( $order->get_transaction_id() && $sent_to_admin )
echo '<p><strong>' . __("Transaction id") . ': </strong>' . $order->get_transaction_id() . '<p>';
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
I got a quick question as I've been researching a couple of hours and have not found a suitable answer.
Id like to send a new type of e-mail when a new order is made and send it to the email address provided in a custom check-out field.
I've implemented Woocommerce and added extra checkout-fields via the plugin (Checkout Field Editor.
One of these check-out fields holds an email address (field name is [client_email]).
I also managed to create a new type of e-mail via the Woo Custom Emails Plugin.
The only problem I have is to set the recipient for this email with the input from the custom checkout field [client_email].
Any thoughts or solutions?
Many thanks!
I'd find this little snippet:
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'processing_order_replacement_email_recipient', 10, 2 );
function processing_order_replacement_email_recipient( $recipient, $order ) {
// Set HERE your replacement recipient email(s)… (If multiple, separate them by a coma)
$recipient = '<email adress>';
return $recipient;
}
And this is the e-mail template file.
<?php
/**
* Customer processing order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-processing-order.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates/Emails
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$email_heading = get_option( 'ec_woocommerce_customer_processing_order_heading' );
/**
* #hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php echo get_option( 'ec_woocommerce_customer_processing_order_main_text' ); ?>
<?php
/**
* #hooked WC_Emails::order_details() Shows the order details table.
* #hooked WC_Structured_Data::generate_order_data() Generates structured data.
* #hooked WC_Structured_Data::output_structured_data() Outputs structured data.
* #since 2.5.0
*/
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
/**
* #hooked WC_Emails::order_meta() Shows order meta data.
*/
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
/**
* #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 );
/**
* #hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
I want to remove the billing address and shipping address from the admin-new-order.php. I already have a duplicate of it in my theme. I was able to remove the email and phone number, but I just cant remove the billing and shipping.
To remove the email and phone I did this
add_filter( 'woocommerce_email_customer_details_fields', 'custom_woocommerce_email_customer_details_fields' );
function custom_woocommerce_email_customer_details_fields( $totals ) {
unset(
$totals['billing_email'],
$totals['billing_phone']
);
return $totals;
}
I know that if I completely removed:
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
it would remove everything, but I can't do that because I need the notes, and delivery times (from a plugin) that displays there. If I delete the whole thing then it deletes everything.
I've tried
unset($totals['billing_first_name']);
And so many variations of this but it doesn't work.
enter image description here
In all email templates you have below do action hook. WC_Emails::email_address() this function code is used for add billing and shipping details in mails.
/**
* #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 );
For remove the billing and shipping detail from mail put bellow function in your function.php file
function removing_customer_details_in_emails( $order, $sent_to_admin, $plain_text, $email ){
$wmail = WC()->mailer();
remove_action( 'woocommerce_email_customer_details', array( $wmail, 'email_addresses' ), 20, 3 );
}
add_action( 'woocommerce_email_customer_details', 'removing_customer_details_in_emails', 5, 4 );
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 :
Class WC_Emails customer_details() method
Class WC_Emails email_addresses() method