1. Home
  2. Knowledge Base
  3. WooCommerce Product Table
  4. Product Table Shortcode Options
  5. Sorting & ordering the product table

Sorting & ordering the product table

WooCommerce Product Table comes with 2 options for sorting the table when it first loads. Once the table has loaded, customers can click on a column heading to sort by that column.

Sort by

The sort_by option controls which column the table is sorted by when first displayed.

If not specified, the WooCommerce default product ordering is used. This can be found under the WooCommerce > Settings > Products > Display menu.

You can sort by any of the following:

  • name (or title) – sort by product name
  • id – sort by product ID (note: this is different to SKU)
  • menu_order – sort by the order listed in the Products menu when in the “Sorting” view
  • date – sort by date published
  • modified – sort by the last modified date
  • price – sort by price
  • popularity – sort by number of sales
  • reviews (or rating) – sort by the average review score
  • rand – apply random ordering

In addition, if you are not using the lazy load option, you can sort by any other column present in the table. E.g. sort_by="description".

For lazy loaded tables, you can only sort by the keywords listed above. This is because the sorting is handled by the server when the products are retrieved from the database.

Examples:

  • Sort using keyword:  [product_table columns="name,tags,categories,price,add-to-cart" sort_by="rating"]
  • Sort using any column in table (when lazy load is disabled):  [product_table columns="sku,image,name,price,add-to-cart" sort_by="sku"]

Sort order

The sort_order option controls the direction in which the table is sorted. Use asc for ascending order or desc for descending order.

The defaults is desc for date sorting and asc for everything else.

Example:

  • [product_table columns="name,price,add-to-cart" sort_by="price" sort_order="desc"]

Can I sort by multiple columns?

No, this is not currently possible. The table can only be sorted by a single column.

Can I sort the table by number?

By default, the table is sorted alphabetically rather than numerically. This applies to all text-based columns including custom fields and taxonomies.

If you’re using custom fields or taxonomies to store numbers instead of text, then you may wish to sort the table in number order. There is no option for this, but you can achieve this by adding the numbers in a format that will make sense when ordered alphabetically. For example:

  • If you add numbers in the format 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and 11, then they will be sorted in the following order – 1, 10, 11, 2, 3, 4, etc. This does not look correct.
  • If you’re sorting by a custom field containing numbers 01, 02, 03, 04, 05, 06, 07, 08, 09, 10 and 11, then they will be sorted correctly both alphabetically and numerically.

How to change the order of the items in the filter dropdowns

Most of the filter dropdowns that you can add above the product table can only be sorted alphabetically. However, it is possible to control the order in which attributes are listed. This is done in WooCommerce rather than our plugin.

WooCommerce attributes list orderThe attributes in the filter dropdowns are sorted according to the ‘Default sort order’ set in Products > Attributes. If you hover over the Name column and click the Edit link, then you will see a page where you can set the ordering.

In the example screenshot, we’ve set the “Brand” attribute to be ordered by ‘Name’ (i.e. alphabetical). ​

If you use ‘Custom ordering’ then you can drag and drop the attributes into the correct order when you edit the ​terms for that attribute (click ‘Configure Terms’ from the Products > Attributes page).

Was this article helpful?

Related Articles