HUSKY - Products Filter Professional for 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 块的样式取决于您的主题。

Ref: https://pluginus.net/support/topic/husky-products-filter-professional-for-woocommerce-solution