HUSKY - Product Filter for WooCommerce

WooCommerce 产品分类描述在筛选后的商店页面不显示

默认情况下,WooCommerce 会在分类归档(分类)页面显示分类描述。然而,当 HUSKY 产品筛选器激活时,商店页面的 URL 会从真正的分类归档变为筛选后的商店页面 — 例如 /shop/?swoof=1&product_cat=my-category。在此类页面上,WordPress 不会加载分类对象,因此任何依赖 is_product_taxonomy() 的代码都无法找到分类,导致描述无法显示。

这是 WordPress 的预期行为,并非 HUSKY 的缺陷。

如需在筛选后的商店页面上显示分类描述,请将以下代码片段添加到主题的 functions.php 文件中,或通过代码片段插件添加:

add_action('woocommerce_before_shop_loop', function() {

    // Exit if this is a normal category page without WOOF filter
    if (is_product_taxonomy() AND empty($_GET['swoof'])) return;

    $term = null;

    // Try to get term from taxonomy archive
    if (is_product_taxonomy()) {
        $term = get_queried_object();
    }

    // If not found, try HUSKY's really_curr_tax parameter
    if ((!$term || is_wp_error($term)) AND !empty($_GET['really_curr_tax'])) {
        $raw     = sanitize_text_field($_GET['really_curr_tax']);
        $term_id = (int) explode('-', $raw)[0];
        if ($term_id > 0) {
            $term = get_term($term_id, 'product_cat');
        }
    }

    // Exit if term not found or has no description
    if (!$term || is_wp_error($term) || empty($term->description)) return;

    echo '<div class="term-description">';
    echo do_shortcode(wp_kses_post(wpautop($term->description)));
    echo '</div>';

}, 5);

此代码片段会从 HUSKY 在 URL 中传递的 really_curr_tax 参数中读取当前分类,并在产品循环前手动输出描述。

注意:.term-description 区块的样式取决于您的主题。

参考链接:https://pluginus.net/support/topic/husky-products-filter-professional-for-woocommerce-solution