ARTICLE AD BOX
I'm using code that displays top-level product categories on all pages of the site.
/* Adding top-level product category */ add_action('woodmart_after_header', 'show_top_level_categories', 30); function show_top_level_categories() { // We exclude the cart, checkout, and thank you pages if (is_cart() || is_checkout() || is_order_received_page()) return; global $wp_query; // We get the ID of the current category $current_category_id = isset($wp_query->queried_object->term_id) ? $wp_query->queried_object->term_id : null; // Getting top-level product categories $categories = get_terms([ 'taxonomy' => 'product_cat', 'parent' => 0, 'hide_empty'=> true, 'orderby' => 'menu_order', 'order' => 'ASC' ]); if (!empty($categories)): ?> <div class="sticky-category"> <div class="content"> <ul class="top-categories"> <?php foreach ($categories as $category): ?> <li <?= ($category->term_id === $current_category_id) ? 'class="active"' : ''; ?>> <a href="<?= esc_url(get_term_link($category->term_id)); ?>"><?= esc_html($category->name); ?></a> </li> <?php endforeach; ?> </ul> </div> </div> <?php endif; }I want to rework this code. How can I display top-level product categories only on specific pages (home page, shop, archive, categories, single product page). What condition should I add, and how do I do it correctly?
1491 gold badge12 silver badges41 bronze badges
2
