Problems ordering by date in a product category

[ad_1]

when I have a category with a custom order, the pre_get_posts that is done, disables the ability to sort by date.

I have solved it by including this in the plugin:

public function sort_products_by_category( $query ) {
	if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'date' )
		return;

	if ( ( is_product_category() || is_product_tag() ) && $query->is_main_query() && ! is_admin() ) {

But of course, aside from not wanting to touch the plugin, I’m sure you have a much more elegant way to do it within your own plugin.

Thank you very much.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer