PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Filters not working with a custom product category base

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Our store has a custom product category base which is /shop.

When we set this and also apply the following rewrite rules so our categories have category pages based on the /shop slug, the filter can't seem to work with the products.

 

add_filter('rewrite_rules_array', function ($rules) {
  $new_rules = array();
  $terms = get_terms(array(
    'taxonomy' => 'product_cat',
    'post_type' => 'product',
    'hide_empty' => false,
  ));
  if ($terms && !is_wp_error($terms)) {
    $siteurl = esc_url(home_url('/'));
    foreach ($terms as $term) {
      $term_slug = $term->slug;
      $baseterm = str_replace($siteurl, '', get_term_link($term->term_id, 'product_cat'));
      // rules for a specific category
      $new_rules[$baseterm . '?$'] = 'index.php?product_cat=' . $term_slug;
      // rules for a category pagination
     $new_rules[$baseterm . '/page/([0-9]{1,})/?$'] = 'index.php?product_cat=' . $term_slug . '&paged=$matches[1]';
     $new_rules[$baseterm . '(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?product_cat=' . $term_slug . '&feed=$matches[1]';
   }
 }
  return $new_rules + $rules;
});

On initial load there's products, but the filters can't filter the products or render the filter options correctly.

Is there a way to fix this?

Hello

Now it seems you have disabled this customization - https://c2n.me/4kaObMC.png

It looks like this custom code is overriding the search query

In this case, you can try playing with this setting - https://share.pluginus.net/image/i20240122120228.png and  https://share.pluginus.net/image/i20240122120311.png