WooCommerce auto complete orders which has products marked as virtual & downloadable type.. while it puts orders into processing not complete status if its a virtual product only.
What if we need to auto complete orders with virtual products too instead of putting it in processing ?
We found this but it auto completes all orders not just the virtual products
/**
* Auto Complete all WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'completed' );
}
We need to auto complete the orders have virtual products as it happens for the orders with products marked as virtual & downlodable