Adding product tables to the category archive template
While WooCommerce Product Table is primarily designed to be used on standard WordPress pages, it can also be used on product category/archive pages by overwriting the product archive template in your theme. This will allow you to automatically display product tables when people view a category page, instead of the usual category layout.
How to add product tables to category archives
1. First create a folder called “woocommerce” in your theme or child theme. If your theme already has this folder, you can skip this step. Upload the folder to your server in this location:
(You can read more about WooCommerce templates here.)
2. Next, download the sample archive-product.php from here, and upload it to the woocommerce folder you just created. It should be in this location:
You should now see product tables displayed on your category pages, displaying products from the current category.
If you don’t see a product table, check the following:
- Is the correct theme active? If you have uploaded your template to the child theme (e.g. flatsome-child) but the parent theme is active, then your template won’t be picked up. In this case you would need to activate the child theme.
- Does your theme have a file called ‘woocommerce.php’? It will be in the theme’s root folder (e.g. /wp-content/themes/<theme>/woocommerce.php). If present, this file will override the arhive-product.php template, so it won’t work. To fix this you will need to delete or rename the woocommerce.php file.
- Do you have a caching plugin? Sometimes this can prevent the new template from being picked up. Try disabling the caching plugin temporarily or clearing the cache.
Changing the shortcode options in the archive template
If you inspect the sample template file, you’ll see on line 59 there is an
$args array. Currently, only the
columns option is set, but you can add more shortcode options here as required.
$args array accepts the same option names which are used in the
[product_table] shortcode. You just need to change the format slightly (e.g.
'option' => 'value') in the
For example, if you wanted to add the
show_quantity option, you would use:
$args = array( 'columns' => 'image,name,price,add-to-cart', 'sort_by' => 'name', 'show_quantity' => true );
Add more shortcode options to suit your requirements (e.g. setting search filters, etc). See this article for the full list of shortcode options.
Using filter widgets on product category archives
WooCommerce Product Table comes with its own set of product filter widgets which you can add to a widgetized area such as a sidebar. These only work for product tables on normal pages and posts. They do NOT work for product tables that have been added to the category archive template.
To use filter widgets on category archives, you need to use the built-in WooCommerce filter widgets instead of the dedicated product table widgets. You can find these in Appearance > Widgets. They start with ‘WooCommerce’ instead of ‘Product Table’ (see screenshot).
Can I use a different shortcode for each category?
The above instructions assume that you’ll have the same shortcode for each category. To dynamically use different shortcodes depending on the current category, you would need to do some extra custom coding.
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.