Hello,
I’m trying to figure out how to order my archive pages and search results by price as a default. I’ve read that the customiser would normally have a setting for this, but I can’t find it anywhere. I’m happy to add a code snippet to my functions.php if that’s an alternative. Can you advise please?
Kindest regards,
Phil.
Hi Phil,
The Ordering option is available in the Appearance > Customize > Product Catelog.
Hope it helps.
Thanks
Hi @tristup
Thanks for that, that’s great. I also want the search results page to be ordered in the same way, I’ve found this snippet to do that. However, the drop-down on the search results page is still showing as “Relevance”, even though the products are ordered by price. Could you help me ensure the dropdown is set to Price by default please? Would that require a template update? Thank you.
add_action( 'woocommerce_product_query', 'my_custom_product_query' );
function my_custom_product_query( $query ) { if( ! $query->is_main_query() )
return;
if( ! isset( $query->query['s'] ) )
return;
$query->set( 'order', 'ASC' );
$query->set( 'orderby', 'price' );
return $query;
}
Hi Phil,
I would suggest you go through the following article, which will help with the sorting and the dropdown option selection.
https://rudrastyh.com/woocommerce/change-defaut-product-sorting.html#with-hook
Hope it helps.
Thanks
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.