0

How can I change the default sorting to not be “custom ordering + name” but “custom ordering + date” ?

I would really make more sense to default sort by date, but also be possible to custom order the items and override the date sorting for some items, but still keep the date sorting for the items which have not beed custom sorted.

enter image description here

It tried to make some function.php snippet, but I couldn’t really make it work:

add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby');
function am_woocommerce_catalog_orderby( $args ) {
    $args['meta_key'] = '';
    $args['orderby'] = 'date order';
    $args['order'] = 'desc';
    return $args;
}
Jonas Borneland
  • 383
  • 1
  • 6
  • 19
  • 1
    Does this answer your question? [In Woocommerce, is there a way to sort my products by "last modified"?](https://stackoverflow.com/questions/69051715/in-woocommerce-is-there-a-way-to-sort-my-products-by-last-modified) – Rajeev Singh Sep 04 '21 at 11:56

1 Answers1

0

Try this code

add_filter('posts_clauses', 'order_by_menu_order_date');
function order_by_menu_order_date($posts_clauses) {
    global $wpdb;
    // only change query on WooCommerce loops
    if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {        
        if($posts_clauses['orderby'] == 'wp_posts.menu_order ASC, wp_posts.post_title ASC') {
            $posts_clauses['orderby'] = "wp_posts.menu_order ASC, wp_posts.post_date DESC ";
        }        
    }
    return $posts_clauses;
}