Change sorting

Change sorting on products that are ‘connected’ to a product

Goes into the functions.php

/**
 * Modify the main query - products sorting on product category pages.
 */
function twstudio_modify_the_main_query( $query ) {
	if ( ! is_admin() && is_product_category() && $query->is_main_query() ) {

		$query->set( 'meta_key', '_sku' );
		$query->set( 'orderby', 'meta_value' );
		$query->set( 'order', 'ASC' );
	}
}
add_action( 'pre_get_posts', 'twstudio_modify_the_main_query' );

Change the orderby and order, to change order.

If you just going to change Standart sorting on all Products. Go to: WooCommerce -> Settings -> Products -> Display -> Default Product Sorting

Leave a Reply

Your email address will not be published. Required fields are marked *