Last active
April 29, 2020 15:42
-
-
Save Spreeuw/febeaaee2d6c78825190c492d1d78e49 to your computer and use it in GitHub Desktop.
WooCommerce Bulk send order details
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 | |
add_action( 'bulk_actions-edit-shop_order', 'woocommerce_bulk_actions_order_emails', 10 ); | |
function woocommerce_bulk_actions_order_emails( $actions ) { | |
$actions['send_order_details'] = __( 'Email invoice / order details to customer', 'woocommerce' ); | |
return $actions; | |
} | |
add_filter( 'handle_bulk_actions-edit-shop_order', 'woocommerce_bulk_actions_order_emails_handle', 10, 3 ); | |
function woocommerce_bulk_actions_order_emails_handle( $redirect_to, $action, $post_ids ) { | |
if ( $action !== 'send_order_details' ) { | |
return $redirect_to; | |
} | |
foreach ( $post_ids as $post_id ) { | |
as_schedule_single_action( time(), 'woocommerce_transactional_email_bulk_process', array( 'order_id' => $post_id ) ); | |
} | |
$redirect_to = add_query_arg( 'send_order_details_queued', count( $post_ids ), $redirect_to ); | |
return $redirect_to; | |
} | |
add_action( 'woocommerce_transactional_email_bulk_process', 'woocommerce_transactional_email_bulk_process', 10, 1 ); | |
function woocommerce_transactional_email_bulk_process( $order_id ) { | |
if ( $order = wc_get_order( $order_id ) ) { | |
do_action( 'woocommerce_before_resend_order_emails', $order, 'customer_invoice' ); | |
// Send the customer invoice email. | |
WC()->payment_gateways(); | |
WC()->shipping(); | |
WC()->mailer()->customer_invoice( $order ); | |
// Note the event. | |
$order->add_order_note( __( 'Order details manually sent to customer.', 'woocommerce' ), false, true ); | |
do_action( 'woocommerce_after_resend_order_email', $order, 'customer_invoice' ); | |
} | |
} | |
add_action( 'admin_notices', 'woocommerce_transactional_email_bulk_process_notice' ); | |
function woocommerce_transactional_email_bulk_process_notice() { | |
if ( !empty( $_GET['send_order_details_queued'] ) ) { | |
printf( '<div class="updated"><p>%d emails added to email queue for immediate sending!</p></div>', intval( $_GET['send_order_details_queued'] ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment