Skip to content

Instantly share code, notes, and snippets.

@kloon
Last active October 27, 2021 04:47
Show Gist options
  • Save kloon/f3dbb792b1c478d55704c8eeb101287b to your computer and use it in GitHub Desktop.
Save kloon/f3dbb792b1c478d55704c8eeb101287b to your computer and use it in GitHub Desktop.
WooCommerce 3.2: Add resend admin order email option that was removed
<?php
/**
* This adds back an option to resend the admin new order email from the order edit screen that was removed in WooCommerce 3.2
*/
/**
* Filter to add a new menu to the dropdown
*
* @param array $actions
* @return array
*/
function add_resend_admin_order_email_action( $actions ) {
$actions['send_admin_order_details'] = __( 'Email order details to Admin', 'woocommerce' );
return $actions;
}
add_filter( 'woocommerce_order_actions', 'add_resend_admin_order_email_action', 10, 1 );
/**
* Hook into newly added send_admin_order_details to handle sending of admin emails
*
* @param $order Order object
* @return void
*/
function resend_send_admin_order_email( $order ) {
// Send the admin new order email.
WC()->payment_gateways();
WC()->shipping();
WC()->mailer()->emails['WC_Email_New_Order']->trigger( $order->get_id(), $order );
// Note the event.
$order->add_order_note( __( 'Order details manually sent to admin.', 'woocommerce' ), false, true );
do_action( 'woocommerce_after_resend_order_email', $order, 'new_order' );
// 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_admin_order_details', 'resend_send_admin_order_email', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment