Stone
Stone

Reputation: 749

My new template file in WooCommerce doesn't work for products with tags

I am new with WooCommerce, and I don't know how to solve this issue. I have product with categories and tag.

In my home page I show two lists, product by tags and product by categories. When I click in my first list I have to show something like this:
(return a list of this tag order by category)

Tag1
Category 1  (2) number of products
Category 2  (4)
Category 3  (1)

and when I click in Category 1, I show a product like product-tag.php file

For do this I override woocommerce plugin and add this in product-tag.php:

if (is_product_category()) :
    include("product-category.php");
  else:
    if (is_product_tag()) :
      include("listTag-product.php");
    endif;
  endif;

listTag-product.php is a new file that I created, but don't work, by default call to product-tag.php.

How to change this?

I want to use product_tag.php when I click in the list "Category 1 (2)" to show the product.

Upvotes: 1

Views: 1187

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253784

The problem is that a product tag can also be a product category or the opposite…

For that reason when using if (is_product_category()) the condition is always true and listTag-product.php will never be included

Looking at WooCommerce templates, I don't see any:

  • product_tag.php template
  • product-category.php template…

The related existing WooCommerce templates are:

  • content-product_cat.php
  • taxonomy-product_cat
  • taxonomy-product_tag.php

After all why split this in 2 templates? You don't need that. You will better use the same template with fine tuned conditions inside it. But using conditionals as is_product_category() and is_product_tag() together is not the solution…

Depending on your thoughts, you could better use categories and subcategories instead of categories and tags.

If you want some real help, it will be better to reconsidering all, changing your approach and beginning to explore other ways. Here in Stackoverflow you will need to make a new question with more details and making available the code used in your templates or scripts, explaining with clarity, what is working and what not… For each problem one question at the time.

References:

Upvotes: 1

Related Questions