0

I want to get the top level category parent which is "wedgwood" so i give it a different menu and different template that what i wrote so far but it dont apply except on ‘wedgwood’ category wegdwood is my top level category i want this to be applied to all categories underneath it

in header.php

if (is_product_category(‘wedgwood’)) {
wp_nav_menu(array(‘menu’=>’wedgwood-menu’ ));
//I want to add here the code that links to another template which is wedgwood-template.php
}

in functions.php

//register the custom menus
function register_my_menus() {
register_nav_menus(
array(‘wedgwood-menu’ => __( ‘Wedgwood Menu’ ))
); }
add_action( ‘init’, ‘register_my_menus’ );

So please i need a solution for this

1 Answer 1

1

WP native function get_queried_object() can help you to get an ID of a currently displayed term.

WooCommerce then includes this handy function: woocommerce_get_term_top_most_parent() (originated here on WPSE btw,) that will get it's top-level parent term.

I haven't tested the following code but it should provide a good starting point:

if ( 'wedgwood' == woocommerce_get_term_top_most_parent( get_queried_object()->term_id )->slug ) {
    // your code-fu here ...
}

Regarding the template redirect part of your question - take a look at:
Creating a default Custom Post Template that a Theme can override

Reference:

1
  • 1
    Looks like woocommerce_get_term_top_most_parent() doesn't exist anymore! Sep 11, 2014 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.