How to trash multiple post/product programmatically

Maybe you can just move the trash function to be inside the foreach loop.

foreach ( $items as $item ) {       
        $product_id = $item['product_id'];
        // matching products are trashed
        if ( has_term( 'machine', 'product_cat', $product_id ) ) {
            wp_trash_post($product_id);
        }
    }