Complete paid orders of virtual products
Paid orders that contain only virtual products (services, memberships, tickets) go straight to Completed instead of waiting in Processing.
<?php
add_filter(
'woocommerce_payment_complete_order_status',
static function ( $status, $order_id, $order = null ) {
$order = $order instanceof WC_Order ? $order : wc_get_order( $order_id );
if ( 'processing' !== $status || ! $order ) {
return $status;
}
foreach ( $order->get_items() as $item ) {
$product = $item instanceof WC_Order_Item_Product ? $item->get_product() : null;
if ( ! $product || ! $product->is_virtual() ) {
return $status;
}
}
return 'completed';
},
10,
3
);
Good to know
Only for payments that complete online (cards, PayPal…). Bank transfer and cash on delivery orders are left as they are.
In these packs
- WooCommerce essentials: The small WooCommerce changes shop owners ask for most.