Code snippet: Sort SKU numbers numerically
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.
WooCommerce Product Table normally sorts SKU values alphabetically. This works well for mixed SKUs that contain letters and numbers, but it may give unexpected results if your SKUs are numbers only. For example, alphabetical sorting can place 100 before 20.
If all your product SKUs are numeric, then you can use the following code snippet to sort the SKU column as numbers.
Code snippet
Add this PHP code to your theme or child theme, or with a code snippets plugin:
add_filter( 'wc_product_table_use_numeric_skus', '__return_true' );
This changes the SKU column sorting so that numeric SKU values are sorted by their number value instead of alphabetically.
Important
Only use this snippet if your SKUs are numbers. If your store uses SKUs that contain letters, hyphens, or mixed formats, then alphabetical sorting is usually more appropriate.