Whole site’s pagination not working after rewriting product permalink

I managed to get it fixed with the advice from tom. This is the solution I tried.

function product_perma_Rewrite() {

    $prodCat = ['taxonomy' => 'product_cat'];
    $categories = get_categories($prodCat);
    $catSlug = [];
    foreach($categories as $category) {
        $catSlug[] = $category->slug;
    }
    
     add_rewrite_rule(
        '^('.implode('|', $catSlug).')/([^/]+)/comment-page-([0-9]{1,})/?$',
        'index.php?post_type=product&category=$matches[1]&product=$matches[2]&cpage=$matches[3]','top'
    );
    
    add_rewrite_rule(
        '^('.implode('|', $catSlug).')/([^/]*)/?',
        'index.php?post_type=product&category=$matches[1]&product=$matches[2]',
        'top'
    );
    
    flush_rewrite_rules();
}
add_action('init', 'product_perma_Rewrite');