Answer the question
In order to leave comments, you need to log in
Woocommerce - how to combine product filter and pagination?
Hello everyone!
I made a filter for products in a category, a simple one:
add_action( 'pre_get_posts', 'custom_products_filter' );
function custom_products_filter( $query ) {
if (!is_product_category() || is_admin()){
return;
}
if (isset($_GET['weight']) && $query->is_main_query()){
$args = ['numberposts' => -1, 'weight' => $_GET['weight']];
$products = wc_get_products($args);
foreach ($products as $product){
$ids[] = $product->get_id();
}
$query->set('post__in', $ids);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question