Displaying product tables in search results
While WooCommerce Product Table is primarily designed to be used on standard WordPress pages, it can also be used in product search results. This is the search results page that customers see after using the ‘Product Search’ widget provided by WooCommerce.
Please note that it’s not possible to use product tables in the general WordPress search results for your whole website. This is because the sitewide search results include other types of content (such as pages and posts), and WooCommerce Product Table can only list products. You can do this using our other table plugin, Posts Table Pro, which lists all types of WordPress content. (Instructions for Posts Table Pro here.)
How to use product tables in WooCommerce search results
- First create a folder called “woocommerce” in your theme or child theme (if it doesn’t already exist). See here for details: https://docs.woocommerce.com/document/template-structure.
- Next, download archive-product.php by clicking the link and then upload it to the “woocommerce” folder. E.g: /wp-content/themes/<my theme>/woocommerce/archive-product.php.
- You should then see product tables on your category pages and product search results. If you inspect this template file, you’ll see on line 59 there is an
$argsarray which is passed to the [product_table] shortcode. In this example template, only the
columnsoption is set, but you can add more shortcode options to this array as required. For example, if you wanted to add the
sort_byoption you would do:
$args = array( 'columns' => 'image,name,price,add-to-cart', 'sort_by' => 'name' );
- Add / edit more shortcode options to suit your requirements (e.g. choosing your columns, setting search filters, etc. – please see our article on Creating Product Tables for instructions).
Can I use product tables on search results but not category archives?
The above instructions will display product tables on search results AND on categories, tags, and the main shop page. This is because by default, WooCommerce uses the same template for all these pages.
If you want to show product tables on some of these pages but not others, then you will need to modify the template using some custom code. This is outside the scope of our standard plugin support. If you don’t know how to do the required coding, then we recommend that you post a job on Codeable where one of their WordPress experts can quote for the work. Alternatively, get in touch if you’d like a quote from our plugin customisations service.