Support » Plugin: WooCommerce » Filter (WooCommerce Layer Nav) no effect on category specific shop loop?

  • Hi,

    Hopefully someone can help! I have a shop using Woocommerce’s built in “Layered Nav” in a widget which allows filtration by product attributes. This works perfectly if the shop displays all categories – so by default. It does not work if I loop a specific category using either of these two methods:

    A Function method:

    add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    function custom_pre_get_posts_query( $q ) {
    
    	if ( ! $q->is_main_query() ) return;
    	if ( ! $q->is_post_type_archive() ) return;
    	
    	if ( ! is_admin() && is_shop() ) {
    
    		$q->set( 'tax_query', array(array(
    			'taxonomy' => 'product_cat',
    			'field' => 'slug',
    			'terms' => array( 'category-main' ),
    			'operator' => 'NOT IN'
    		)));
    	
    	}
    
    	remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }

    – (note this above shows everything else but the chosen product_cat.)

    or in page (archive-product.php) to just show a chosen cat:

    $args = array(
        'post_type' => 'product',
        'product_cat' => 'category-main',
        'posts_per_page' => 4
        );
    $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) {
        while ( $loop->have_posts() ) : $loop->the_post();
            wc_get_template_part( 'content', 'product' );
        endwhile;
    } else {
        echo __( 'No products found' );
    }
    wp_reset_postdata();

    However, both of these methods stop the filter from working.
    ?filter_attributeName=nameOne,nameTwo
    This, as a query, shows no different results: all results from the selected product_cat are listed regardless of filtered attributes.

    What I need to know is how can I process the ?filter before/after the loop runs?

    Last note: this is stock Woocommerce and stock Layered Nav widget.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • edmundcwm

    (@disillusia)

    Hi Jack,

    I’m facing the exact same issue.

    Just wondering if you found a fix for it?

    Regards,
    Edmund

    Hi Guys,

    I’m also experiencing this exact same issue after updating a client’s site from woocommerce 2.5 to 3.03. All filtering on category landing’s is suddenly broken…

    Just wondering if either of your ever found a fix?

    thanks!

    – jason

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filter (WooCommerce Layer Nav) no effect on category specific shop loop?’ is closed to new replies.