仅为 WooCommerce 单个产品页面中的某些产品隐藏选项卡

Hiding tabs only for some products in WooCommerce single product pages

我想知道如何仅在某些单个产品页面上隐藏或删除 WooCommerce 选项卡(如果可能的话,使用 css 或 jquery 将它们保留在其他页面上)?

Woocommerce div 标签:class="woocommerce-tabs wc-tabs-wrapper"

删除某些单一产品上的 WooCommerce 标签非常容易。您可以使用 CSS 轻松完成此操作。每个 WC 产品都有一个唯一的产品 ID,请检查此 http://prntscr.com/dp2c79 ,您将使用浏览器检查元素或源代码找到它。 然后查找产品 ID 只需使用 'Display: none' 标签作为该产品 ID。

示例:#product-834 .tabs {显示:none !important;}

此致,

可以使用专用的 woocommerce_product_tabs 过滤器挂钩仅删除某些产品的标签(在单个产品页面上):

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;

}

代码进入您的活动子主题的 function.php 文件(活动主题或任何插件文件)。

此代码已经过测试并有效。

基于原始的 WooCommerce 片段:Editing product data tabs