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