Here’s a javascript you can use to automatically complete WooCommerc orders from any status. This example uses the ‘processing’ status.
add_action(‘woocommerce_order_status_changed’, ‘ts_auto_complete_virtual’);
function ts_auto_complete_virtual($order_id)
{
if ( ! $order_id ) {
return;
}
global $product;
$order = wc_get_order( $order_id );
if ($order->data[‘status’] == ‘processing’) {
$virtual_order = null;
if ( count( $order->get_items() ) > 0 ) {
foreach( $order->get_items() as $item ) {
if ( ‘line_item’ == $item[‘type’] ) {
$_product = $order->get_product_from_item( $item );
if ( ! $_product->is_virtual() ) {
// once we find one non-virtual product, break out of the loop
$virtual_order = false;
break;
}
else {
$virtual_order = true;
}
}
}
}
// if all are virtual products, mark as completed
if ( $virtual_order ) {
$order->update_status( ‘completed’ );
}
}
}
For a full explanation, check out this blog post How to automatically Complete WooCommerce orders when they go to the Processing status.