我在我的功能中为我的产品页面添加了其他选项卡。php文件,现在需要将其包装在if语句中,以便其他选项卡仅显示在“模型”类别内的产品上我已经尝试了我能找到的每一种方法,但都不管用。它们都会去掉每个页面上的附加选项卡,即使它属于指定的类别。
我试过上面提到的所有东西this question, 我假设他们都没有工作过,因为那个人正在编辑他们的单个产品。php文件,我正在编辑我的函数。php文件?
if ( is_product() && has_term( \'Models\', \'product_cat\' ) ) {
////Add Custom Tabs
add_filter( \'woocommerce_product_tabs\', \'woo_new_product_tab\' );
function woo_new_product_tab( $tabs ) {
// Adds a compare tab
$tabs[\'compare\'] = array(
\'title\' => __( \'Compare\', \'woocommerce\' ),
\'id\' => \'compare\',
\'priority\' => 50,
\'callback\' => \'woo_compare_tab_content\'
);
// Adds a warranty tab
$tabs[\'warranty\'] = array(
\'title\' => __( \'Warranty\', \'woocommerce\' ),
\'id\' => \'warranty\',
\'priority\' => 50,
\'callback\' => \'woo_warranty_tab_content\'
);
return $tabs;
}
function woo_warranty_tab_content() {
$warranty = get_post_meta( get_the_ID(), \'wpcf-warranty\', true );
// Warranty Tab Content
echo \'<div class="fusion-title title sep-double">\';
echo \'<h3 class="title-heading-left">Warranty</h3>\';
echo \'<div class="title-sep-container"><div class="title-sep sep-double"></div></div>\';
echo \'</div>\';
echo "$warranty";
}
function woo_compare_tab_content() {
$compare = get_post_meta( get_the_ID(), \'wpcf-compare\', true );
// Comparison Tab Content
echo \'<div class="fusion-title title sep-double">\';
echo \'<h3 class="title-heading-left">Compare</h3>\';
echo \'<div class="title-sep-container"><div class="title-sep sep-double"></div></div>\';
echo \'</div>\';
echo "$compare";
}
}