Woocommerce single product - template by categorie

2019-01-20 06:37发布

Already posted question but not working for me, so I'm asking a little help guys... ;)

There is my single-product.php (woocommerce file line:28)

 <?php if ( is_product_category( 'customcateg' ) ) 
    {
       woocommerce_get_template_part( 'content', 'single-product-customcateg' ); }
else {      
       woocommerce_get_template_part( 'content', 'single-product' ); } 
  ?>

I have in my theme/woocommerce 3 files:

  • single-product.php
  • content-single-product.php
  • content-single-product-customcateg.php

The files contains different php codes (the customcateg has to be protected from visitors, and some roles; this part is already done...)

When i try to access a product who is in "customcateg", it shows me the normal "single-product" template....

I tried to put :

 <?php if ( is_product_category( 'customcateg' ) ) 
    {
       woocommerce_get_template_part( 'content', 'single-product-customcateg' ); }
else {      
       woocommerce_get_template_part( 'content', 'single-product-customcateg' ); } 
  ?>

It simply show the single-product, but it has to show the customcateg one, but it does not. It only does when I pust the "single-product-customcateg.php" content in the "single-product.php" ...

What's wrong guys ?

Please help me :)

Thanks a lot by advance,

1条回答
做自己的国王
2楼-- · 2019-01-20 07:20

It's looking for a file titled content-single-product-customcateg.php

That file doesn't exist so it's falling back to the default.

if ( has_term( 'customcateg', 'product_cat' ) ) {
    woocommerce_get_template_part( 'content', 'single-product-customcateg' );
} else {
    woocommerce_get_template_part( 'content', 'single-product' );
}

Can you add the contents of your content-single-product-customcateg.php by the way?

查看更多
登录 后发表回答