Last active
October 18, 2023 10:38
-
-
Save railmedia/d029745eac3686949680eb76ea7c426f to your computer and use it in GitHub Desktop.
Order WooCommerce products by slug
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
| function order_woo_products_by_slug( $query ) { | |
| if ( ! is_admin() && $query->is_main_query() ) { | |
| // Not a query for an admin page. | |
| // It's the main query for a front end page of your site. | |
| if ( is_woocommerce() || is_tax( 'product_cat' ) ) { | |
| // It's the main query for a WooCommerce category archive or for a WooCommerce page | |
| $query->set( 'orderby', 'name' ); | |
| $query->set( 'order', 'ASC' ); | |
| } | |
| } | |
| } | |
| add_action( 'pre_get_posts', 'order_woo_products_by_slug' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment