Code snippet: Disable sorting when column headings are clicked
Please note: this article is aimed at developers. We have provided an article on how to add code snippets. If you're not comfortable using them then you can use our plugin customization service.
By default, customers can click a column heading in WooCommerce Product Table to sort the table by that column. If you want to keep the column headings visible but stop customers from sorting the table, then you can use the following code snippet.
Code snippet
Add this PHP code to your theme or child theme, or with a code snippets plugin:
add_filter( 'wc_product_table_column_sortable', 'barn2_wpt_disable_column_sorting', 10, 2 );
function barn2_wpt_disable_column_sorting( $sortable, $column_name ) {
return false;
}
This disables sorting when customers click any column heading in the table. The table will still use the default sort order from your product table settings, shortcode, or table builder.
Disable sorting for one column only
To disable sorting for a specific column only, check the column name before returning false. For example, this snippet disables sorting for the product name column:
add_filter( 'wc_product_table_column_sortable', 'barn2_wpt_disable_name_column_sorting', 10, 2 );
function barn2_wpt_disable_name_column_sorting( $sortable, $column_name ) {
if ( 'name' === $column_name ) {
return false;
}
return $sortable;
}
Replace name with the column that you want to make non-sortable.