A
A
awe2018-03-14 07:25:12
WordPress
awe, 2018-03-14 07:25:12

How to override product sorting?

Each category of the store has a meta field, where product ids are indicated separated by commas. In which file and how to override the output of category products in the order specified in the category metafield?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arthur, 2018-03-14
@ART_CORP

I don’t think there is a ready-made version, you can make a plugin for these tasks

I
Ivan Kozlov, 2018-03-15
@trampick

In a vein like yours, you need to catch the moment when the user is in the category.
Can be done with a hook

add_action( 'pre_get_posts', 'filters_modify_main_query' );
function filters_modify_main_query( $query ) {
  if ( strpos( '_' . $_SERVER['REQUEST_URI'], '/product-category/' ) > 0 && $query->is_main_query() ) {
           //change query
        }
  return $query;
}

Well, where is the change query to prescribe the order by id.
It is better to implement this through the position metafield in the product and specify sorting by the metafield. This will be the most correct option.
In your case, if you specify the order in the taxonomy metafield, you can’t do without crutches.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question