仅在WooCommerce中的已定义子类别归档页面上输出自定义代码

时间:2017-09-21 11:59:06

标签: php wordpress woocommerce categories product

实际上在WooCommerce中,我试图仅在已定义的产品子类别存档页面中显示一些自定义代码(视频)。

这是我正在使用的代码:

<?php if( has_term('viola-chan','product_cat' $tag_ID=18) ) { ?>
 my video html code
<?php } ?> 

但它不起作用,也出现在其他父页面上。

Here is a live link

如何仅在WooCommerce中在已定义的子类别存档页面上输出自定义代码?

2 个答案:

答案 0 :(得分:1)

由于这与在产品类别档案页面上显示内容有关,因此您应该使用:

<?php if( is_product_category( 'viola-chan' ) ) { ?>
    <div>my video html code here</div>
<?php } ?>

但&#34;中提琴&#34;应该是你的子类别......

相关文档:WooCommerce Conditional Tags: Product category page

答案 1 :(得分:0)

尝试第三个变量post id,如下所示:

global $post;
if(has_term( 'viola-chan','product_cat', $post->ID )) {
    //do something if post has viola-chan term
}else{
    //do something else if the post don't have viola-chan term
} 

参考 - https://wordpress.stackexchange.com/questions/166576/if-product-is-in-sub-category-show-code