0

I am trying to create a custom category for woocommerce product.Then I want fetch data of particular category.here is my taxonomy code,

// Register Custom Taxonomy

    add_action( 'init', 'custom_taxonomy_Item' );
    function custom_taxonomy_Item()  {
    $labels = array(
        'name'                       => 'Items',
        'singular_name'              => 'Item',
        'menu_name'                  => 'Item',
        'all_items'                  => 'All Items',
        'parent_item'                => 'Parent Item',
        'parent_item_colon'          => 'Parent Item:',
        'new_item_name'              => 'New Item Name',
        'add_new_item'               => 'Add New Item',
        'edit_item'                  => 'Edit Item',
        'update_item'                => 'Update Item',
        'separate_items_with_commas' => 'Separate Item with commas',
        'search_items'               => 'Search Items',
        'add_or_remove_items'        => 'Add or remove Items',
        'choose_from_most_used'      => 'Choose from the most used Items',
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'item', 'product', $args );
    register_taxonomy_for_object_type( 'item', 'product' );
    } 

After this I am creating a custom taxonomy template "taxonomy-product_cat-Item.php " In my theme woo-commerce directory .After this I am unable to fetch data of particular category . honestly I have no idea how to do this .Any Help

1

Your template name should be: taxonomy-item.php. It should be taxonomy slug, without product-cat.

  • Aniruddha Gawade@in woo-commerce directory or in theme directory – Sanjay Yadav Nov 9 '17 at 5:28
  • Try putting it in Theme directory. – Aniruddha Gawade Nov 9 '17 at 5:30
  • Aniruddha Gawade@taxonomy-product_cat-Item.php this is working . – Sanjay Yadav Nov 9 '17 at 5:31
  • On your template print get_queried_object to check if proper tax is selected. – Aniruddha Gawade Nov 9 '17 at 5:36
  • Aniruddha Gawade@problem is that I am not able to crate custom template for product custom taxonomy is " taxonomy-item.php" and taxonomy-product_cat-Item.php not working – Sanjay Yadav Nov 9 '17 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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