簡體   English   中英

僅在 WooCommerce 單個產品頁面中隱藏某些產品的選項卡

[英]Hiding tabs only for some products in WooCommerce single product pages

我想知道如何僅在某些單個產品頁面上隱藏或刪除 WooCommerce 選項卡(如果可能,使用 css 或 jquery 將它們保留在其他頁面上)?

Woocommerce div 標簽: class="woocommerce-tabs wc-tabs-wrapper"

可以使用專用的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 片段: 編輯產品數據選項卡

刪除某些單個產品上的 WooCommerce 選項卡非常容易。 您可以使用 CSS 輕松完成此操作。 每個 WC 產品都有一個唯一的產品 ID,請檢查此http://prntscr.com/dp2c79 ,您將使用瀏覽器檢查元素或源代碼找到它。 查找產品 ID 然后只需使用該產品 ID 的“顯示:無”選項卡。

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

問候,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM