Auto-Complete Paid Orders for Virtual Products
Marks paid orders as Completed instead of Processing when every item is virtual, such as services, memberships or event tickets.
Opens WPIDE on
Code
add_filter( 'woocommerce_payment_complete_order_status', function ( $status, $order_id, $order = null ) {
if ( 'processing' !== $status ) {
return $status;
}
$order = $order instanceof WC_Order ? $order : wc_get_order( $order_id );
if ( ! $order || ! $order->get_items() ) {
return $status;
}
foreach ( $order->get_items() as $item ) {
$product = is_callable( array( $item, 'get_product' ) ) ? $item->get_product() : null;
if ( ! $product || ! $product->is_virtual() ) {
return $status;
}
}
return 'completed';
}, 10, 3 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.