WC category product order by date

Hello,
I’m using the WC Archive layout and by default the products are sorted alphabetically:
https://www.intimolerose.it/categoria-prodotto/donna/
How can I change this setting? For example by making sure that the order of appearance is by date?
Thanx

Hi @scenaryo,

Thanks for reaching out.
If you are using any of the predefined templates where the Products element has been used, it can’t be possible to change the order. You can mention the Order into the Query Builder of the Looper Provider as shown in the screenshot.

Screenshot-1143-

Hope it helps.
Thanks

Hi @tristup,
Yes, I’m using a predefined template because there are tons of categories on the site and I can’t make a layout for each category, it would take too long.
However, the change in the order is necessary, how could I solve it? Acting on the php files in any way?

Hi @scenaryo,

You need some WooCommerce filter to change the product order to by date. An example code below will change the order by published date. You need to add the code in your child theme functions.php

add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
  $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    $args['orderby'] = 'published_date';
    $args['order'] = 'ASC';
  return $args;
}

Reference: https://woocommerce.com/document/custom-sorting-options-ascdesc/

Please note that custom code is outside the scope of our support. Issues that might arise from the use of custom code and further enhancements should be directed to a third party developer or you can avail One where we can answer questions outside of the features of our theme.

Hope that helps.

It works! Thank you very much!

Hi @scenaryo,

You’re welcome! If you have any other concerns or clarifications regarding our theme features, feel free to open up a new thread.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.