Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WooCommerce: Set default order on shop page to by price, title or date
* Change the default shop page 'catalogue' order of how products are displayed
* You can use the following parameters:
* 'menu_order' – by the custom order first, then by product name (Default)
* 'popularity' – by the number of sales
* 'rating' – by the average rating
* 'date' – recently added products will be displayed first
* 'price' – cheapest products will be displayed first
* 'price-desc' – the most expensive first
* 'rand' – in a random order
* @param $sort_by
* @return string
function zpd_wc_default_shop_page_orderby( $sort_by ): string {
* You can add conditions to this function - example changing the default ordering of a specific category
if( is_product_category( 'nicknacks' ) ) {
return $sort_by; // no changes for nicknacks category
return 'price-desc';
add_filter('woocommerce_default_catalog_orderby', 'zpd_wc_default_shop_page_orderby', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment