Created
July 12, 2021 14:01
-
-
Save jorpdesigns/c8d104793cfb65afcedbda162a9047ab to your computer and use it in GitHub Desktop.
Snippet to set default ordering for specific WooCommerce product category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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