Ecommerce Shopify WordPress Discussion

Can't send customer note email notification in WooCommerce

I have the following code to try to send an order notification email to the customer in WooCommerce. I have some other code that already made the custom order status "reminder". I can also select this new "reminder" from the Bulk actions dropdown box in the orders page in WooCommerce. If a select an order and select custom order status "reminder" from the dropdown box it successfully adds a note on the order on that order's page, but it does not send a notification email to the user. How come? // Do the bulk action from the selected orders add_filter('handle_bulk_actions-edit-shop_order', 'status_bulk_action_edit_shop_order', 10, 3); function status_bulk_action_edit_shop_order($redirect_to, $action, $post_ids) { if ($action === 'reminder') { foreach ($post_ids as $post_id) { $order = wc_get_order($post_id); $the_order_id = $order->get_id(); $note = 'Test1'; $order->update_status('reminder'); send_order_note_email($the_order_id, $note); } } return $redirect_to; } function send_order_note_email($order_id, $note) { // Get the order object $order = wc_get_order($order_id); // Check if order exists and is a valid order if (!$order) { return; } // Add the note to the order $order->add_order_note($note); // Send the email notification $mailer = WC()->mailer()->get_emails()['WC_Email_Note_Customer']; if ($mailer) { $mailer->trigger($order_id, $note); } } Tried various functions and different hooks.
You are making things much more complicated: The WC_Order method add_order_note() has an additional argument $is_customer_note that need to bet set to 1 or true, and send automatically the customer_note email notification by itself. You can use 2 approaches: Add a note to customer when order status get changed to "reminder" (the cleanest way and complete way): // Do the bulk action from the selected orders add_filter('handle_bulk_actions-edit-shop_order', 'status_bulk_action_edit_shop_order', 10, 3); function status_bulk_action_edit_shop_order($redirect_to, $action, $post_ids) { if ($action === 'reminder') { foreach ($post_ids as $post_id) { $order = wc_get_order($post_id); $order->update_status('reminder'); } } return $redirect_to; } // Add a note to customer when order get "reminder" status (sends the email notification) add_action('woocommerce_order_status_reminder', 'add_reminder_order_note_to_customer', 10, 2); function add_reminder_order_note_to_customer( $order_id, $order ) { // Define the customer note to be sent $note_to_customer = 'Test1'; // Add the customer note to the order $order->add_order_note($note_to_customer, 1); } Add a note to customer when changing order status to "reminder" via bulk actions: // Do the bulk action from the selected orders add_filter('handle_bulk_actions-edit-shop_order', 'status_bulk_action_edit_shop_order', 10, 3); function status_bulk_action_edit_shop_order($redirect_to, $action, $post_ids) { if ($action === 'reminder') { foreach ($post_ids as $post_id) { $order = wc_get_order($post_id); $order->update_status('reminder'); // Define the customer note to be sent $note_to_customer = 'Test1'; // Add the customer note to the order $order->add_order_note($note_to_customer, 1); } } return $redirect_to; } Code goes in functions.php file of your child theme (or in a plugin). Both ways should work.

January 27, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.