Woocommerce view all products button link working on shop catalogue but not on search

Hi experts, I am having a problem with woocommerce, on online store...added code to add a view all link inside woocommerce, template pagination.php and functions.php...the button works for the shop catalogue but not for search page, when i run a search for e.g. business, products are displayed but paginated, though the 'view all button' not working here..need help with getting the view all/view less button to work on the search page, help will be much appreciated.  You can test on bookworldzambia.com
Kasonde NeddyDesigner & DeveloperAsked:
Who is Participating?
 
eemitConnect With a Mentor Commented:
You should use is_search() in pagination.php file:
This Conditional Tag checks if search result page archive is being displayed.

And you need something like this in your "View All" link in pagination.php file:
href="<?php echo esc_url( add_query_arg( array( 's' => urlencode(get_query_var('s') ), 'post_type' => get_post_type(), 'view' => 'all' ), home_url("/") ) ); ?>"

Open in new window


Post here your <your current theme>/woocommerce/loop/pagination.php file
0
 
Kasonde NeddyDesigner & DeveloperAuthor Commented:
I have the following in my functions.php

//NUMBER OF PRODUCTS TO DISPLAY ON SHOP PAGE
add_filter('loop_shop_per_page', 'wg_view_all_products');

function wg_view_all_products(){
      if($_GET['view'] === 'all'){
            return '9999';
      }
}

I need to add a function, filter that will do the same on the search page, search.php, i need to add filter to the search page so the view all button works on the search page..hope I am clear and the above works
0
 
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Correction...the view all button just redirects me to the homepage..and does not work in the search page
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Correction...the view all button just redirects me to the homepage..and does not work in the search page
0
 
eemitCommented:
What happens if you change your "view all" link on Search Result page
from:
http://www.bookworldzambia.com/?view=all
to e.g.:
http://www.bookworldzambia.com/?s=business&post_type=product&view=all
0
 
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Hi eemit,

How can I do so?  Where would I change it, I think you are right...not sure where to amend that, in search page code in wordpress, or functions.php?  Thanks for your response
0
 
eemitCommented:
Hi kasondeneddy,
as I can see you have implemented this.
Let us know if you have any other questions about this issue.
0
 
Kasonde NeddyDesigner & DeveloperAuthor Commented:
This was very helpful, and indeed the answer to the problem!
0
 
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Hi eemit,

I've been unwell and away from the work, thanks for your help, your answer helped get it right!
0
All Courses

From novice to tech pro — start learning today.