HUSKY - Product Filter for WooCommerce

Avada 主题:WooCommerce 筛选在分页时丢失(修复)

有时在Avada主题中使用HUSKY Filter时,导航到第2页或任何后续分页页面时,筛选条件会丢失。筛选在第1页正常工作,但在点击类似/page/2/的分页链接时完全失效。

症状:

  • 第1页筛选正常:https://example.com/shop/fltr/product_cat-category/
  • 第2页筛选丢失:https://example.com/shop/fltr/product_cat-category/page/2/
  • 显示所有产品而非筛选结果

根本原因

该问题由Avada的Avada_Woocommerce类中的shop_template_loader()方法引起,该方法在使用自定义商店页面模板时会修改WordPress查询对象。

有问题的代码位置:/wp-content/themes/Avada/includes/class-avada-woocommerce.php

要解决此问题,请将以下代码添加到当前WordPress主题的functions.php文件中:

add_action('template_redirect', function() {
    global $wp_query;
	
    // If WOOF is filtering
    if (is_woof_search_going()) {
        $wp_query->is_search = true;
    }
    
}, 1); // Priority 1 - VERY early, before everything

来源https://pluginus.net/support/topic/pagination-showing-incorrect-page-count-and-404-errors-with-avada-husky-filter/?part=2