Reputation: 259
I have created a new taxonomy for products on WooCommerce. Now, when I go to the taxonomy view, it shows error 404.
How do I make it show the products just like in any other regular category on the site?
Upvotes: 2
Views: 8304
Reputation: 328
After creating a new custom WooCommerce taxonomy you may need to refresh the WordPress permalink settings from:
Admin Panel -> Settings -> Permalinks
You only have to open the page and WordPress will refresh it automatically.
Note: Don't forget to clear the cache of your site if you are using a caching plugin!
Upvotes: 0
Reputation: 61
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
Upvotes: 3
Reputation: 11808
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.
Upvotes: 2