categories - WooCommerce IF statements not working

I am trying to use the WooCommerce Conditional Tags to only include a template into specific product pages. However my

I am trying to use the WooCommerce Conditional Tags to only include a template into specific product pages. /

However my statements aren't working, and they show on all pages. I'd like to NOT display my template in a specific category and its product pages:

<?php 
 // Show in Shop Page OR NOT in Products IDs 15852,15859,15863,15866 OR NOT Category Archive Gift Cards

 if ( is_shop() || !is_product(array( 15852,15859,15863,15866 )) ||  !is_product_category( 'gift-cards' )) 
 { 
      get_template_part('my-template'); 
 } 
 ?>

I've also tried the opposite:

<?php 
if ( is_product(array('gift-card-25','gift-card-50','gift-card-75','gift-card-100')) ) 
{ 
    get_template_part('my-template'); 
} 
?>

Can you please advise how to get it to work?

Our website:

Thanks!

I am trying to use the WooCommerce Conditional Tags to only include a template into specific product pages. https://docs.woocommerce/document/conditional-tags/

However my statements aren't working, and they show on all pages. I'd like to NOT display my template in a specific category and its product pages:

<?php 
 // Show in Shop Page OR NOT in Products IDs 15852,15859,15863,15866 OR NOT Category Archive Gift Cards

 if ( is_shop() || !is_product(array( 15852,15859,15863,15866 )) ||  !is_product_category( 'gift-cards' )) 
 { 
      get_template_part('my-template'); 
 } 
 ?>

I've also tried the opposite:

<?php 
if ( is_product(array('gift-card-25','gift-card-50','gift-card-75','gift-card-100')) ) 
{ 
    get_template_part('my-template'); 
} 
?>

Can you please advise how to get it to work?

Our website: https://grindersforlife/shop

Thanks!

Share Improve this question edited Jan 15, 2020 at 5:49 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Jan 14, 2020 at 0:45 CintiaCintia 391 gold badge1 silver badge7 bronze badges 2
  • Can you please show us the code source – Younes.D Commented Jan 14, 2020 at 1:03
  • I've fixed my question to include my code. Sorry! Thanks for your help! – Cintia Commented Jan 14, 2020 at 4:41
Add a comment  | 

1 Answer 1

Reset to default 1

The solution to my problem was to use:

has_term( 'the-cat-I-want-to-display', 'product_cat' ) || is_product_category( 'the-cat-I-want-to-display' )

This worked. Thanks everyone for your help!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744835014a4596210.html

相关推荐

  • categories - WooCommerce IF statements not working

    I am trying to use the WooCommerce Conditional Tags to only include a template into specific product pages. However my

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信