简体   繁体   English

删除除一页之外的所有页面上的标签

[英]delete tabs in on all pages except one

I would like to remove an explicit tab in our shop.我想删除我们商店中的一个显式标签。 Generally no problem either.一般也没问题。 But: I would like to keep it in one category (ID = 15)但是:我想将其归为一类(ID = 15)

I found this code to remove the tabs on special pages我发现此代码可以删除特殊页面上的选项卡

what needs to be changed now?现在需要改变什么?

 add_filter( 'woocommerce_product_tabs', 'conditionaly_removing_product_tabs', 99 );
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 targeted categories (Ids, slugs or names) <=== <=== <===
$product_cats = array( 'clothing', 'posters' );
// If the current product have the same ID than one of the defined IDs in your array,…
// we remove the tab.
if( has_term( $product_cats, 'product_cat', $product_id ) ){
// 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;
}```

Ok, I am not a woocommerce expert and neither have worked with it.好的,我不是 woocommerce 专家,也没有使用过它。 However, knowing wordpress and how get terms work .. you could try some thing as follow.但是,了解 wordpress 以及 获取术语的工作原理……您可以尝试以下操作。

    add_filter( 'woocommerce_product_tabs', 'conditionaly_removing_product_tabs', 99 );
 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 targeted categories (Ids, slugs or names) <=== <=== <===
    // $product_cats = array( 'clothing', 'posters' );

    // lets get all terms and then programatically exclude certain categories
    $terms = get_terms( 'product_cat', array(
                    'orderby' => 'name',
                    'order'   => 'ASC',
                    'exclude' => array( 77, 71 ), // dont forget to include ids for the categories
    ));

    // Loop over the tabs and remove them from the categories
    array_map(function($term) use ($product_id, $tabs){
        if ( has_term($term, 'product_cat', $product_id)){
            unset( $tabs['description'] ); // (Description tab)
            unset( $tabs['reviews'] ); // (Reviews tab)
            unset( $tabs['additional_information'] ); // (Additional information tab)
        }
    }, $terms);

  return $tabs;

}

thanks for your answer!感谢您的回答! But it doesnt work... maybe we have to be different here ...但它不起作用......也许我们必须在这里有所不同......

I have a code in the functions.php with which I add a custom tab.我在functions.php 中有一个代码,我用它添加了一个自定义选项卡。 (This is also the tab that should only be displayed "ONLY" in the future in a certain product category. (这也是将来在某个产品类别中应该只显示“ONLY”的选项卡。

//Preisvorschlag Produkt-Tab hinzufügen
add_filter( 'woocommerce_product_tabs', 'wp_bibel_de_add_woocommerce_product_tabs' );

function wp_bibel_de_add_woocommerce_product_tabs( $tabs ) {
    $tabs['wp_bibel_de_custom_tab'] = array(
        'title'     => __( 'Requests' ),
        'priority'  => 50,
        'callback'  => 'wp_bibel_de_new_product_tab_callback'
    );

    return $tabs;
}

the category ID in which this tab should be displayed is: 228应显示此选项卡的类别 ID 为:228

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM