Possible Solution:
function mail_to_customer_on_downloads_remaining_change ( $post_id, $post_data )
{
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || $post_data["post_type"] != "shop_order" )
{
return;
}
global $wpdb;
$downloads_remaining_db = $wpdb->get_results( "SELECT
downloads_remaining
FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions
WHERE order_id
= $post_id", ARRAY_A );
$downloads_remaining_post = $_POST["downloads_remaining"];
for ( $i=0; $i < count($downloads_remaining_db); $i++ )
{
if ( !in_array($downloads_remaining_db[$i]["downloads_remaining"], $downloads_remaining_post) )
{
$old_text = esc_html( 'We have finished processing your order.', 'woocommerce' );
$new_text = 'we have reset the download limits in your order. You can now download the files again:';
$order = wc_get_order( $post_id );
$order_id = $order->get_id();
$billing_email = $order->get_billing_email();
$mailer = WC()->mailer();
$recipient = $billing_email;
$subject = 'Download limits in your order #' . $order_id . ' changed';
$content = wc_get_template_html( 'emails/customer-completed-order.php', array(
'order' => $order,
'email_heading' => 'Order #' . $order_id,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $mailer
) );
$content = str_replace( $old_text, $new_text, $content);
$headers = "Content-Type: text/html\r\n";
$mailer->send( $recipient, $subject, $content, $headers );
return;
}
}
}
add_action( 'pre_post_update', 'mail_to_customer_on_downloads_remaining_change', 10, 2 );