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ブロックのスタイリングは、テーマによって異なります。

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