【发布时间】:2018-01-30 12:11:03
【问题描述】:
我正在使用来自此答案的代码:
Hiding tabs only for some products in WooCommerce single product pages
代码如下:
add_filter( 'woocommerce_product_tabs', 'conditionaly_removing_product_tabs', 98 );
function conditionaly_removing_product_tabs( $tabs ) {
// Get the global product object
global $product;
// Get the current product ID
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
// Define HERE your targetted products IDs in this array <=== <=== <===
$target_products_ids = array(123,152,162);
// If the current product have the same ID than one of the defined IDs in your array,…
// we remove the tab.
if(in_array($product_id, $target_products_ids)){
// KEEP BELOW ONLY THE TABS YOU NEED TO REMOVE <=== <=== <=== <===
unset( $tabs['description'] ); // (Description tab)
unset( $tabs['reviews'] ); // (Reviews tab)
unset( $tabs['additional_information'] ); // (Additional information tab)
}
return $tabs;
}
此代码可以很好地取消设置或隐藏特定产品的标签。
相反,我想取消设置或隐藏特定产品类别的标签。
我怎样才能为产品类别做到这一点?
【问题讨论】:
标签: php wordpress woocommerce categories product