我试图使用WooCommerce条件标记只将模板包含到特定的产品页面中。https://docs.woocommerce.com/document/conditional-tags/
然而,我的声明不起作用,它们显示在所有的页面上。我不想在特定类别及其产品页面中显示我的模板:
<?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');
}
?>我也尝试过相反的方法:
<?php
if ( is_product(array('gift-card-25','gift-card-50','gift-card-75','gift-card-100')) )
{
get_template_part('my-template');
}
?>你能告诉我怎么让它起作用吗?
我们的网站:https://grindersforlife.com/shop
谢谢!
发布于 2020-01-15 07:20:48
解决我的问题的办法是使用:
has_term( 'the-cat-I-want-to-display', 'product_cat' ) || is_product_category( 'the-cat-I-want-to-display' )
这个成功了。谢谢大家的帮助!
https://wordpress.stackexchange.com/questions/356311
复制相似问题