How do I make an archive template for custom woocommerce taxonomy?

I have created a new taxonomy for products on woocommerce.

Now, when I go to the taxonomy view and it shows 404.
how do i make it show the products just like in any other regular category on the site?

Read More

tnx ahead 🙂

Related posts

Leave a Reply

2 comments

  1. I tried this code and it works for me.

    I created a taxonomy name ‘team’ and here is my code.

    add_filter('template_include', 'team_set_template');
    function team_set_template( $template ){
      if(is_tax('team')) :
        $taxonomy = 'team';
        $term = get_query_var($taxonomy);
        $prod_term = get_terms($taxonomy, 'slug='.$term.''); 
        $term_slug = $prod_term[0]->slug;
        $t_id = $prod_term[0]->term_id;
        $term_meta = get_option( "taxonomy_$t_id" );
        $term_meta['team_access_pin'];  
    
        wc_get_template( 'archive-product.php' );
    
     else : 
    
        wc_get_template( 'archive-product.php' );
    
     endif; 
    
    }
    

    Note: I used this code in functions.php file. If anyone wants to use this code. Please replace the name ‘team’ with your custom taxonomy name.

    Thanks,
    Satya

  2. This problem occurs when WordPress does not find any template for the custom taxonomy.

    1.The solution is to create a WooCommerce template named as “taxonomy-tax_name.php” (ideally in a child theme).
    2.For this you could copy the contents of an archive template like archive-product.php and modify it by doing a WP_Query() with arguments for post_type=>”product” and add a “tax_query” with the newly made custom taxonomy slug.
    3.This would get you the required products and now can be displayed as required.