Title: Custom category sort order
Last modified: October 7, 2020

---

# Custom category sort order

 *  Resolved [doffine](https://wordpress.org/support/users/doffine/)
 * (@doffine)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/custom-category-sort-order/)
 * Hey there WooCommerce support & enthusiasts,
 * to change the default sort order of only a single product category we just used
   the good working code snippet…
 *     ```
       //custom function to override default sort by category
       function custom_default_catalog_orderby() {
       //choose categories where default sorting will be changed
       if (is_product_category( array( 'category1', 'category2', 'category3' ))) {
           return 'date'; // sort by latest
       }else{
       return 'popularity'; // sort by popularity as the default
         } // end if statement
       } //end function
   
       add_filter( 'woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby' ); //add the filter
       ```
   
 * found at [https://webhostingbuddy.com/blog/woocommerce-default-sort-method-for-specific-category/](https://webhostingbuddy.com/blog/woocommerce-default-sort-method-for-specific-category/)
 * Now this code works as charm, but it sets all “other” categories per default 
   to a static value like in this case “popularity”.
 * This overrides the setting made in WooCommerce.
 * For this code to be not only super but ingenious we would like that not a static
   order like “popularity” is used when the initial categories don’t apply, but 
   simply the order setting made in WooCommerce itself. That would be fantastic!
 * So does anyone have an idea how we could modify the code passage…
 *     ```
       }else{
       return 'popularity'; // sort by popularity as the default
       }
       ```
   
 * … to something like “else return ‘order setting made in WooCommerce'”?
 * With many thanks in advance,
    -doffine

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/custom-category-sort-order/#post-13505628)
 * The default value is sent to your function as a parameter, so return that.
 *     ```
       function custom_default_catalog_orderby( $default_orderby ) {
       ...
       return $default_orderby;
       ```
   
 *  Thread Starter [doffine](https://wordpress.org/support/users/doffine/)
 * (@doffine)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/custom-category-sort-order/#post-13508933)
 * [@lorro](https://wordpress.org/support/users/lorro/), you are our personal hero!
   This works perfectly, we already tested it. Great!
 * I mark this as resolved now.
 * Many thanks again for this help and idea,
    -doffine

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom category sort order’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [code](https://wordpress.org/support/topic-tag/code/)
 * [custom sort order](https://wordpress.org/support/topic-tag/custom-sort-order/)
 * [snippet](https://wordpress.org/support/topic-tag/snippet/)

 * 2 replies
 * 2 participants
 * Last reply from: [doffine](https://wordpress.org/support/users/doffine/)
 * Last activity: [5 years, 7 months ago](https://wordpress.org/support/topic/custom-category-sort-order/#post-13508933)
 * Status: resolved