-
-
Save Sanabria/42e8c4c36ed03e411fa367e3f1e26eba to your computer and use it in GitHub Desktop.
WooCommerce - Add send customer order notes email option
This file contains hidden or 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