Change the sort order of WooCommerce Grouped Products

Switch from menu order to product date

WooCommerce has a small army of filters and hooks that you could customize almost every aspect of the plugin. If you have a grouped product the default display method is by menu_order. But recently, someone wanted to display the grouped items by the date they were published.

This is very easily accomplished by filtering the $args being passed through the woocommerce_grouped_children_args filter. WooCommerce queries for the child products in the grouped product via WP_Query so you can essentially use any parameter supported by WP_Query. In this case, we only need to change the orderby parameter to date and since we’d like the most recent items first, we swap the order parameter to descending.

add_filter( 'woocommerce_grouped_children_args', 'kia_grouped_children_args' );
function kia_grouped_children_args( $args ){
    $args['orderby'] = 'date';
    $args['order'] = 'DESC';
    return $args;
}
Code language: PHP (php)

If you need help understanding filters, I wrote what I think is a pretty good tutorial on how to use filters. It took me a while to understand them, but once you do they are very powerful and let you make a lot of customizations.

If you aren’t seeing any changes, chances are that the grouped product’s children have already been stored in a transient. You will need to delete this transient to see changes right away. You can clear all WooCommerce product transients via the Admin. Navigate to WooCommerce>System Status>Tools and click on the button to clear transients.

3 thoughts on “Change the sort order of WooCommerce Grouped Products

    1. kathy Post author

      Yup! woocommerce_product_query is simply run when WooCommerce filters pre_get_posts so both ways will work just fine for products. à+

Comments are closed.