-
-
Save pacmanito/c1109ccdac9f738d5fdc26b94f02fce6 to your computer and use it in GitHub Desktop.
WooCommerce - Add send customer order notes email option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This adds an option to send order notes email manually via order actions drop-down. | |
*/ | |
/** | |
* Filter to add a new menu to the dropdown | |
* | |
* @param array $actions | |
* @return array | |
*/ | |
function add_send_order_notes_email_action( $actions ) { | |
$actions['send_customer_order_notes'] = __( 'Email last order note to Customer', 'woocommerce' ); | |
return $actions; | |
} | |
add_filter( 'woocommerce_order_actions', 'add_send_order_notes_email_action', 10, 1 ); | |
/** | |
* Hook into newly added send_customer_order_notes to handle sending of customer emails | |
* | |
* @param $order Order object | |
* @return void | |
*/ | |
function send_order_notes_email ( $order ) { | |
// Send the customer new order email. | |
WC()->payment_gateways(); | |
WC()->shipping(); | |
$latest_notes = wc_get_order_notes( array( | |
'order_id' => $order->get_id(), | |
'limit' => 1, | |
'orderby' => 'date_created_gmt', | |
'type' => 'customer', | |
)); | |
foreach ( $latest_notes as $latest_note ) { | |
$last_note = $latest_note->content; | |
} | |
WC()->mailer()->emails['WC_Email_Customer_Note']->trigger(array( | |
'order_id' => $order->get_id(), | |
'customer_note' => $last_note | |
)); | |
// Note the event. | |
$order->add_order_note( __( 'Order notes manually sent to customer.', 'woocommerce' ), false, true ); | |
// Change the post saved message. | |
add_filter( 'redirect_post_location', array( 'WC_Meta_Box_Order_Actions', 'set_email_sent_message' ) ); | |
} | |
add_action( 'woocommerce_order_action_send_customer_order_notes', 'send_order_notes_email', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment