Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 12, 2021 14:01
Show Gist options
  • Save jorpdesigns/c8d104793cfb65afcedbda162a9047ab to your computer and use it in GitHub Desktop.
Save jorpdesigns/c8d104793cfb65afcedbda162a9047ab to your computer and use it in GitHub Desktop.
Snippet to set default ordering for specific WooCommerce product category
<?php
// orderby values are date, menu_order, popularity, rating, date, price, price-desc
add_filter( 'woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby' );
function custom_default_catalog_orderby() {
if ( is_product_category( array( 'category-1-slug', 'category-2-slug' ) ) ) { // Replace with your category slugs
return 'menu_order';
} else {
return 'date';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment