Search code examples
phpwordpresswoocommercelayered-navigation

How to make Woocommerce layered nav widget works on products page


I added Woocommerce layered nav widget to my shop's sidebar. Main page shows categories, when user clicks on some category, page will show subcategories and after choosing subcategory, user will see products.

My problem is that layered nav widget works only on page showing categories. But I want to make it work on page which shows products only.

If somebody knows in which function Woocommerce selects which products to show on the page it will be really helpful.

Thank you.

UPD: I found that in widgets/class-wc-query.php in function get_layered_nav_chosen_attributes() $_GET looks like working incorrectly. When I try to filter products in subcategories or products lists, I see in $_GET following values:
[q] => /product-category/category-name/subcategory_name/filter_brand=brand_name
[query_type_brand] => or

When I filter products from categories list I see that filter_brand was correctly parsed and treated as a separate GET parameter.
If somebody knows what is the problem please help me.

UPD2: at this time I have workaround. In class-wc-widge-layered-nav.php get_page_base_url() function after $link calculation I added fake argument like 'a=1'. So now all necessary arguments are parsed correctly. So at this time I don't know the root cause of the behavior. I'm newbie to PHP and Wordpress:)


Solution

  • I resolved the issue. The root cause was incorrect nginx configuration.

    location {
        try_files $uri $uri/ /index.php?q=$uri$args
    }
    

    So my nginx added unnecessary $uri.
    The correct value is:

    try_files $uri $uri/ /index.php?$args