Remove product-category slug plugin works with 1 subcategroy not with 2

In my setup i know there are max 3 params, so this is my solution

add_filter('request', function( $vars ) {
    global $wpdb;

    if(isset($vars['error'])){
        $lastVar = basename($_SERVER['REQUEST_URI']);
        $vars['attachment'] = $lastVar;
    }
    ........rest off code........
}