WooCommerce filter woocommerce_email_actions
-
Hello to everyone,
I have a problem with using WooCommerce “woocommerce_email_actions” it send me the email twice, this is the details.
I need to have a new specific order status so I add this code to the functions.php:
add_action( 'init', 'register_custom_post_status', 20 ); function register_custom_post_status() { register_post_status( 'wc-dispatched', array( 'label' => _x( 'Dispatched', 'Order status', 'woocommerce' ), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( 'Dispatched <span class="count">(%s)</span>', 'Dispatched <span class="count">(%s)</span>', 'woocommerce' ) ) ); } // Adding custom status 'dispatched' to order edit pages dropdown add_filter( 'wc_order_statuses', 'custom_wc_order_statuses', 20, 1 ); function custom_wc_order_statuses( $order_statuses ) { $order_statuses['wc-dispatched'] = _x( 'Dispatched', 'Order status', 'woocommerce' ); return $order_statuses; }So I can see the new order status in the order page, then I created a new plugin to send an email to the customer when this new status is selected.
This is the code of the plugin file:
function add_dispatched_order_woocommerce_email($email_classes){ // include our custom email class require_once( 'includes/class-wc-dispatched-order-email.php' ); // add the email class to the list of email classes that woocommerce loads $email_classes['WC_Dispatched_Order_Email'] = new WC_Dispatched_Order_Email(); return $email_classes; } //Add the actions to Woocommerce default actions function add_dispatched_order_woocommerce_actions($actions){ $actions[] = 'woocommerce_order_status_dispatched'; return $actions; } //Check if the plugin is enabled and add this filters add_action('plugins_loaded', 'woocommerce_dispatched_order_email_plugin_init'); function woocommerce_dispatched_order_email_plugin_init() { add_filter('woocommerce_email_classes', 'add_dispatched_order_woocommerce_email'); add_filter('woocommerce_email_actions', 'add_dispatched_order_woocommerce_actions'); }The email template is a 100% copy of the “customer-completed-order.php” I changed only completed by dispatched.
Everyhting is OK but the problem is I receive two emails of the new order status when the order status is changed to “dispatched”.
Do you have an idea to resolve this and receive only one email?
Thanks in advance
Best regards
The topic ‘WooCommerce filter woocommerce_email_actions’ is closed to new replies.