To auto-complete orders that only contain specific products, use the following snippet, replacing the product IDs:
How to Setup Snippet
Replace the numbers below with the IDs of the products you want to auto-complete. You can have as many or as few products as you like!
add_action( 'woocommerce_payment_complete_order_status', 'snippetpress_auto_complete_specific_products_order', 10, 2 );
function snippetpress_auto_complete_specific_products_order( $status, $order_id ) {
$order = wc_get_order( $order_id );
$product_ids = array( // Replace the numbers below with the IDs of the products you want to auto-complete. You can have as many or as few products as you like!
10,
18,
28,
46,
);
$order_items = $order->get_items();
foreach ( $order_items as $item ) {
$product_id = $item->get_product_id();
if( ! in_array( $product_id, $product_ids ) ){
break;
}
$status = 'completed';
}
return $status;
}