WooCommerce filter grouped products sort order

By June 4, 2015 php

As you have mentioned, you just need to filter the $args being passed through the woocommerce_grouped_children_args filter.


add_filter( 'woocommerce_grouped_children_args', 'so_29973708_grouped_children_args' );
function so_29973708_grouped_children_args( $args ){
    $args['orderby'] = 'date';
    $args['order'] = 'DESC';
    return $args;
}

If you need help understanding filters, I wrote what I think is a pretty good tutorial on how to use filters

Update 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.


SNIPPETS
CHANGE THE SORT ORDER OF WOOCOMMERCE GROUPED PRODUCTS
Switch from menu order to product date

Posted on May 6, 2015. Leave a comment
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;
}

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.

filtersgrouped productswoocommerce
Bookmark the permalink.

Bottom Text Here