WooCommerce is a fantastic e-commerce platform for WordPress. It is well created to handle a few or a lot of products and it comes with a lot of features standard. For a recent project, however, I needed to display recent products and sort by SKU numbers. After a bit of looking around, I came up with a pretty solution: use WordPress WP_Query.
WP_Query is a WordPress class that deals with retrieving posts. You can set a number of parameters that filter what you want and what you don’t. In my case, I was looking for a way to sort items, and in particular, sort by meta key (_sku). So below, you’ll see the code that you can use however you want.
$args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => 12, 'orderby' => 'meta_value', 'meta_key' => '_sku', 'order' => 'ASC' ); $products = new WP_Query($args);
This code is by no means complete in itself, but will get you started. I hope this helps you in your project. If you have any questions or suggestions, please share them in the comments section.