woocommerce pagination_link() keeps adding parameters to url

<div class="product-list-pagination clearfix">
<?php
    $page_url = esc_url_raw(remove_query_arg( array('add-to-cart'), get_pagenum_link( 999999999, false )));
    echo $page_url;
    echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
        'base'         => str_replace( 999999999, '%#%',  $page_url),
        'format'       => '',
        'add_args'     => False,
        'current'      => max( 1, get_query_var( 'paged' ) ),
        'total'        => $wp_query->max_num_pages,
        'prev_text'    => 'previous',
        'next_text'    => 'next',
        'type'         => 'list',
        'end_size'     => 3,
        'mid_size'     => 3,
        'show_all'     => False,
    ) ) );
?>

I am having a problem with this code if the URL in browser URL bar is like this:

Read More
http://localhost/vplay/shop/page/4/?orderby=date&add-to-cart=115

after page link are added instead of removing add-to-cart=115 from URL it keeps adding both parameters to the page URL
I want my URL be something like this:

http://localhost/vplay/shop/page/4/?orderby=date

Notice when I am echoing $page_url variable the URL is fine after using it in paginate_links() function it keeps adding all parameters
now what should I do to prevent that?

Related posts

1 comment

  1. add_action('add_to_cart_redirect', 'resolve_dupes_add_to_cart_redirect');
    
    
    
    function resolve_dupes_add_to_cart_redirect($url = false) {
        if(!empty($url)) { return $url; }
    
         return get_bloginfo('wpurl').add_query_arg(array(), remove_query_arg('add-to-cart'));
    }
    

    Insert the above to your function.php will solve the problem. It did for me.

Comments are closed.