I need to change the default product sorting option to \"Newness\" for a specific product category on my site. I know you can go to WooCommerce > Settings > Product > Displa
Here better and WORKING solution
add_filter('woocommerce_get_catalog_ordering_args', 'woocommerce_catalog_orderby');
function woocommerce_catalog_orderby( $args ) {
if( is_product_category( 'shirts' ) ) { // <- define category slug- returns true or false
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC'; // <- order ASC or DESC
$args['meta_key'] = '_price'; // <- _price is meta_value_num's key - required
}
return $args;
}
Please also read about WP_Query order & orderby here: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters