• Resolved Treebeard

    (@malawimama)


    I’ve searched and tried so many different code snippets, but none seem to work.

    GOAL: Show the Product Search Form at the top of ONLY the “Parts” category and it’s subcategories.

    Right now, I’m using the following code in my woocommerce.php template, and it only shows the search form on the top category, Parts, and not on any of it’s subcategories:

    <?php
            if ( is_product_category(76) || cat_is_ancestor_of(76, get_query_var( 'cat' )) ) {
                get_product_search_form();
                echo '<hr>';
            } 
        ?>

    I also tried this:

    <?php
            if (is_product_category( 'parts' ) || cat_is_ancestor_of( 76, get_queried_object()->term_id) ) {
            get_product_search_form();
            echo '<hr>';
            } else {   
                //
            }
        ?>

    and various other things.

    Anyone have any idea how to do this?

    thanks!

Viewing 1 replies (of 1 total)
  • Hi @malawimama,

    The conditional tag cat_is_ancestor_of() will only work with post categories and not product categories. The display name of them is the same “category” but they are different taxonomies.

    There isn’t a conditional tag to check for product categories like cat_is_ancestor_of. What you could do is just make an array of all the sub-categories like this:

    
    is_product_category( array( 'parts', 'category-next' ) )
    

    See if that doesn’t get you there.

Viewing 1 replies (of 1 total)
  • The topic ‘cat_is_ancestor_of not working. My brain is cooked!!’ is closed to new replies.