仅在 WooCommerce 中的定义子类别存档页面上输出自定义代码
Output custom code on a defined sub category archive pages only in WooCommerce
实际上在 WooCommerce 中,我试图仅在定义的产品子类别存档页面中显示一些自定义代码(视频)。
这是我使用的代码:
<?php if( has_term('viola-chan','product_cat' $tag_ID=18) ) { ?>
my video html code
<?php } ?>
但它不起作用,它也出现在其他父页面上。
如何在 WooCommerce 中仅在定义的子类别存档页面上输出自定义代码?
尝试第三个变量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
因为这与在产品类别档案页面上显示某些内容有关,您应该改用:
<?php if( is_product_category( 'viola-chan' ) ) { ?>
<div>my video html code here</div>
<?php } ?>
但是 "viola-chan" 应该是您的子类别...
实际上在 WooCommerce 中,我试图仅在定义的产品子类别存档页面中显示一些自定义代码(视频)。
这是我使用的代码:
<?php if( has_term('viola-chan','product_cat' $tag_ID=18) ) { ?>
my video html code
<?php } ?>
但它不起作用,它也出现在其他父页面上。
如何在 WooCommerce 中仅在定义的子类别存档页面上输出自定义代码?
尝试第三个变量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
因为这与在产品类别档案页面上显示某些内容有关,您应该改用:
<?php if( is_product_category( 'viola-chan' ) ) { ?>
<div>my video html code here</div>
<?php } ?>
但是 "viola-chan" 应该是您的子类别...