Auto hide empty product table columns

This facility is useful when you have created a product table template that you are re-using on different pages to print different sets of woocommerce product results from the same table by changing the shortcode options, but some of the columns end up being empty when the products being displayed in the table are not related to the empty columns’ property. In such a case use this facility to automatically hide the empty columns.

Use case example scenario

For example let’s say you have created a product table with this shortcode:

[product_table id="123"]

Now you are using this same product table on different pages to print different sets of product results on each page by changing its “category” shortcode option. Let’s say you are using these shortcode variations for the product table to show products with category “clothes” and “books”:

[product_table id="123" category="clothes"]
[product_table id="123" category="books"]

Problem to resolve

Now suppose the product table has a column displaying “book author” which is useful when you are displaying woocommerce products with the category “books”. And you have another column in the same table called “size” which is useful when showing products with category “clothes”.

But this creates a problem – when you are showing category “clothes” through the product table the “book author” column remains empty as it is irrelevant to products with category “clothes”. And while showing “books” category through the product table the “size” columns remains empty as it is irrelevant to books.

Solution via this facility

To fix this issue you can use the hide_empty_columns option that is going to automatically hide all empty columns in the table. You just need to make a small modification to both your product table shortcodes like this :

[product_table id="123" category="clothes" hide_empty_columns="true"]
[product_table id="123" category="books" hide_empty_columns="true"]

Now the “size” column will simply not appear when showing products with “clothes” category via the product table and the “book author” column will not appear when showing books through the same table as this facility detects and removes any empty columns from the table.

Facility information in table editor

The product table plugin provides several shortcode options to make it easier for you to create fewer tables while displaying wide variety of product results from the same table template. Information for this specific shortcode options is listed in the table editor at this location:

auto hide empty product table columns