Forums Forums Search & Filter Pro Issues with ‘Custom Results’ & pagination (Woocommerce)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #251887

    Hi guys,

    So I’m wanting to implement Search & filter with Woocommerce, but using the ‘custom’ option instead of the usual, ‘Woocommerce -Shop’ method. Reason is I need the URL to change upon filtering for some dynamic content to work.

    I have implemented the Search & filter form like so (in my theme’s product archive .php):

    	<?php
    		
    do_action("search_filter_query_posts", 65646);
    
    		if ( fl_woocommerce_version_check( '3.4.0' ) ? woocommerce_product_loop() : have_posts() ) {
    
    			/**
    			 * Hook: woocommerce_before_shop_loop.
    			 *
    			 * @hooked wc_print_notices - 10
    			 * @hooked woocommerce_result_count - 20 (FL removed)
    			 * @hooked woocommerce_catalog_ordering - 30 (FL removed)
    			 */
    			do_action( 'woocommerce_before_shop_loop' );
    			woocommerce_product_loop_start();
    			
    			
    
    			if ( wc_get_loop_prop( 'total' ) ) {
    			    
    
    				while ( have_posts() ) {
    					the_post();
    
    					/**
    					 * Hook: woocommerce_shop_loop.
    					 *
    					 * @hooked WC_Structured_Data::generate_product_data() - 10
    					 */
    					 
    
    					do_action( 'woocommerce_shop_loop' );
    
    					wc_get_template_part( 'content', 'product' );
    				}
    			}
    
    			woocommerce_product_loop_end();
    
    			/**
    			 * Hook: woocommerce_after_shop_loop.
    			 *
    			 * @hooked woocommerce_pagination - 10
    			 */
    			do_action( 'woocommerce_after_shop_loop' );
    		} else {
    			/**
    			 * Hook: woocommerce_no_products_found.
    			 *
    			 * @hooked wc_no_products_found - 10
    			 */
    			do_action( 'woocommerce_no_products_found' );
    		}
    		?>
    

    This works successfully, and the dynamic content works exactly as I require. However, using this method the pagination doesn’t work at all. It works when I take ‘do_action(“search_filter_query_posts”, 65646)’ out of the above, but of course I need this to get into the query for the search. The pagination also works correctly when I use the ‘Woocommerce – Shop’ method, but I don’t get the URL rewrite this way.

    Am I adding the Search & filter form into the Woocommerce product query the right way? Could you please direct me how to manually integrate my Search & filter form into a Woocommerce product query properly?

    If I can’t get this way to work another method would be to rewrite the URL on filter somehow… I’m using the ‘sandf_change_search_url_rewrite()’ function provided elsewhere in the forum to change the URL when I search. Is there a similar way to change the URL when i filter too (without using the ‘Custom’ method)?

    Basically I have a dynamic banner showing on the home page which only shows if it’s the front page. going to myhomepage.com/thehomepageslug removes this banner, even though it’s the same actual page. This way the user will be able to stay on the same page and filter, without the banner appearing. I hope this makes sense.

    Here’s the site in development: https://kit-kings.com/

    Thanks for your assitance,

    Trevor
    #251947

    It looks OK, but I would have set the Ajax Container to .products and the pagination container to .woocommerce-pagination a

    A good test is to disable Ajax. Does it work then? If it does, then it may just be these settings.

    Anonymous
    #251951

    Hi Trevor,

    Thanks for the fast response.

    So the pagination doesn’t actually work with Ajax disabled either. If I take the below code out of the code though, it does.

    do_action("search_filter_query_posts", 65646);

    With the ‘woocommerce – shop’ method the pagination + Ajax does work correctly. This makes me think it’s not an issue with the css selectors and maybe the way it’s implementing the filter into the query?

    Trevor
    #251955

    That could be so, but, as the query is not being run in that template, the method you have used would have been what I tried.

    Are you able to use pre_get_posts to attach the filter?

    Anonymous
    #252992

    Hi Trevor,

    I fixed the issue now, had to revert to the Woocommerce – shop and change a few things. Can close the ticket.

    Thanks,

    Trevor
    #253077

    Thanks for getting back to me.

Viewing 6 posts - 1 through 6 (of 6 total)