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.

Was this article helpful?

Related Articles