Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 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:

share|improve this answer
1  
Looks like woocommerce_get_term_top_most_parent() doesn't exist anymore! –  Alexandre Lavoie Sep 11 at 19:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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