How to use categories in WooCommerce Product Table
WooCommerce Product Table fully supports product categories. You can add a 'categories' column to the product table, sort by category, filter by category, or even list products from specific categories or sub-categories. This article summarizes the different ways in which you can use categories with WooCommerce Product Table.
Category Columns
You can list product categories as a column in the table. Simply add a 'Categories' column when you build the table via Products → Product Tables. You can rename the column to anything you like using the pencil icon.
On the front end, the categories column will list all the categories that each product is in. If a product is in multiple categories then they will appear in a comma separated list.
Parent and child categories/sub-categories are treated identically in the categories column. For example, in the following screenshot, 'T-shirts' is a child category of 'Clothing':
Read the documentation on how to create product category columns.
Displaying products with a specific category or sub-category
There are two ways to list products from a specific category only: by adding a shortcode to a page, or by automatically using the product table layout on all category archive pages.
Listing products by category
There are 2 ways to create a table listing products from a specific category, both of which are available via the table builder in Products → Tables:
- Enable the product table layout on the category template in your store. Customers can then navigate to the category pages in the usual way, and they will see a product table containing the products from that category.
- Create a pre-built table listing products from the selected category(ies) and then insert the table onto your site using the 'Product Table' Gutenberg block or the shortcode from the final page of the table builder. This is a good way to pre-filter the table by category.
Read the documentation on how to list products based on category.
Filtering by category
There are two ways to let customers filter the table to refine the list of products based on their categories:
- Filter dropdown lists above the table.
- Use WooCommerce Product Table with a third party filter plugin to create category filter widgets
Read the documentation on creating category filter dropdowns.
Sorting by category
You can sort the table by category - either when the table first loads, or by allowing customers to click on the header of the category column to sort by category.
If a product is in multiple categories then the first category will be used for sorting.
Can I list categories and sub-categories separately?
WooCommerce Product Table treats categories and sub-categories in exactly the same way, and doesn't distinguish between the two.
The only ways to list categories and sub-categories separately are:
- Add a categories filter above the table, and the dropdown will list the categories in a hierarchical structure with the sub-categories nested/indented under the top level categories.
- Use the table builder to create multiple tables, each listing products from a different subcategory. You can then add multiple tables to the same page. For example, if your 'clothing' category has sub-categories for 't-shirts' and 'hoodies' then you can create two products tables, one listing t-shirts and the other listing hoodies.