I
I
IvanRu082020-04-26 22:33:24
WordPress
IvanRu08, 2020-04-26 22:33:24

How to solve 404 error when changing product quantity per WooCommerce page?

The output of products is divided into 3 pages - 1 product per page (3 products in total). At the bottom there is a drop-down list where you can select the number of products on each page. The problem is this:

  1. When we are on page 1 and change the number of products, for example, to 5 (get request), then everything works OK. Pagination is removed and all products are displayed on one page. The site address changes from site.ru to site.ru?prod-count=5
  2. But such a trick no longer works on the second page and beyond. Because when you select 5 positions per page (and I remind you that there are only 3 products) at site.ru/page/2?prod-count=5 , there is no longer any page and you get a 404 error


It seems to be quite obvious situation, but I do not understand how to solve this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2020-04-27
@IvanRu08

If there, when choosing the number of records per page, the ?prod-count=5 parameter is simply added to the current URL and the browser is sent to this new URL, then the easiest way is to hang the handler for this get request somewhere on template_redirect. See if there is a prod-count GET parameter, if so, look at which page you are on, how many results WC_Product_Query has in total, how many prod-count asks to display. You think, and if it turns out that page X will not exist for you, redirect to the one you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question