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);
        }
    }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)