← Back to All Snippets

Auto-Complete Virtual and Downloadable WooCommerce Orders on Successful Payment

⚡ Target: functions.php 🔒 Tested: WP 6.6+ / PHP 8.2+ 💻 Lang: PHP
PHP (functions.php)
add_action( 'woocommerce_thankyou', 'tipwp_autocomplete_virtual_orders', 10, 1 );
function tipwp_autocomplete_virtual_orders( $order_id ) {
    if ( ! $order_id ) return;
    
    $order = wc_get_order( $order_id );
    if ( ! $order || $order->get_status() !== 'processing' ) return;
    
    $is_virtual_only = true;
    foreach ( $order->get_items() as $item ) {
        $product = $item->get_product();
        if ( $product && ! $product->is_virtual() && ! $product->is_downloadable() ) {
            $is_virtual_only = false;
            break;
        }
    }
    
    if ( $is_virtual_only ) {
        $order->update_status( 'completed', __( 'Auto-completed virtual order by TipWP snippet.', 'woocommerce' ) );
    }
}

Automatically marks orders containing only virtual or downloadable products as Completed immediately after successful payment.

← Back to All Snippets Explore Dev Tools →