'Add custom bulk action "send email invoice" to orders list in Woocommerce

enter image description here

Hello How are you? I dont know how to bulk this action "email invoice /order details to customer" sometimes i have 70 orders that I need to send the email, and i have to do it one by one, i found some codes here but for other actions and i dont know how i can add that one, thanks a lot for the help!

function write_to_file($date_initial, $date_final) {
    global $attach_download_dir, $attach_download_file;

    // Opens/creates file
    $myfile = fopen($attach_download_dir . '/' . $attach_download_file, "w") or die("Unable to open file!");

    // Populates first line
    fwrite($myfile, 'Date; Parent Order ID; Order ID' . PHP_EOL);

    // Retrieves orders data
    if ( isset($date_initial) && isset($date_final) ) $args = array( 'date_created' => $date_initial . '...' . $date_final );
    if ( isset($date_initial) && empty($date_final) ) $args = array( 'date_created' => '>=' . $date_initial );
    if ( empty($date_initial) && isset($date_final) ) $args = array( 'date_created' => '<=' . $date_final );
    if ( empty($date_initial) && empty($date_final) ) $args = array( );
    $orders = wc_get_orders( $args );

    // Populates file with orders data
    foreach ($orders as $order) {
        $order_data = $order->get_data();
        fwrite($myfile,
            // Date of order creation
            $order_data['date_created']->date('d/M/Y') . '; ' .

            // Parent Order ID
            '#' . ( ( $order->get_type() === 'shop_order' ) ? $order->get_id() : $order->get_parent_id() ) . '; ' .

            // Order ID
            '#' . $order->get_id()
        )
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source