如何删除 woocommerce 选项卡?

How to remove woocommerce tab?

我们的 woocommerce 商店中的产品不需要任何默认选项卡,因此我设法禁用了它们,因为我只需要在产品下方显示产品描述,而我想保留实际描述,我相信选项卡本身是多余的,因为没有任何其他选项卡。

基本上,我想完全删除选项卡的标题,但保留其下方的内容框而不修改 woocommerce 核心 php 模板文件。有没有办法为我的 WordPress 主题 functions.php 添加过滤器?

function woocommerce_default_product_tabs( $tabs = array() ) {
    global $product, $post;

    // Description tab - shows product content
    if ( $post->post_content ) {
        $tabs['description'] = array(
            'title'    => __( 'Description', 'woocommerce' ),
            'priority' => 10,
            'callback' => 'woocommerce_product_description_tab'
        );
    }

虽然 CSS 很棒,但如果样式表加载不正确,您最终可能会在无意中向某人显示标签。最好在加载(服务器端)之前通过使用过滤器删除内容,如您所提到的。

请参阅下面的 Woothemes 提供的用于取消设置数据选项卡的代码。
编辑 放在主题中的 functions.php 文件中。

add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );

function woo_remove_product_tabs( $tabs ) {
    unset( $tabs['description'] );          // Remove the description tab
    unset( $tabs['reviews'] );          // Remove the reviews tab
    unset( $tabs['additional_information'] );   // Remove the additional information tab
    return $tabs;
}

编辑 如@BasvanDijk 所述 要完全删除,您可以使用以下

add_filter( 'woocommerce_product_tabs', '__return_empty_array', 98 );

如果您想从 woo-commerce 产品详细信息页面中删除标签,请将此代码添加到您的 function.php

选项 1-

转到 functions.php 并添加以下代码。 (转到管理面板 > 外观 > 编辑器 > functions.php)

add_filter( 'woocommerce_product_tabs', 'woo_remove_tabs', 98 );
function woo_remove_tabs( $tabs ){
    if(is_product()){
      unset( $tabs['description'] ); // Remove the description tab
      unset( $tabs['reviews'] ); // Remove the reviews tab
      unset( $tabs['additional_information'] ); // Remove the additional information tab
      }
  return $tabs;
 }

通过使用此过滤器,我们可以从 Woocommerce 产品页面中删除标签。

选项 2-

或者对于另一种方法,只需将其添加到您的 functions.php

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10);

选项 3-

通过将此添加到 woocommerce.css

的底部来隐藏选项卡
 .woocommerce_tabs .tabs {
    display: none;
}

Read more -Woo-commerce: Remove tab from product page

这是工作代码:

add_filter( 'woocommerce_product_tabs', 'wcs_woo_remove_reviews_tab', 98 );
function wcs_woo_remove_reviews_tab($tabs) {
unset($tabs['reviews']);
return $tabs;
}

对不起,问题不仅在于删除标签,还在于保留产品描述。如果您曾经尝试过上面的代码,您会发现在删除标签时,您实际上是在删除产品描述。这不是理想的情况。

您应该在某处添加以下代码以将其添加回来。但不幸的是,这次您可以在图片旁边添加描述并制作一个窄栏。我找不到将其很好地添加到以前存在选项卡的图片下方的解决方案。 代码:

function woocommerce_template_product_description() {
    woocommerce_get_template( 'single-product/tabs/description.php' );
}

add_action( 'woocommerce_single_product_summary',  'woocommerce_template_product_description', 40 );

出于某种原因,添加到 functions.php 文件的代码对我不起作用,即使它在 woo commerce codex 中也是如此。

我收到了很多针对这些显示评论的产品的垃圾评论。

最后,我使用内置 wordpress/woocommerce 功能从所有产品中手动删除了评论选项卡。

  1. 转到产品列表页面
  2. 单击复选框以 select 所有产品(它只会 select 此页面上的产品,因此您可能需要翻阅几页才能重复)
  3. 从批量操作下拉列表中,select编辑
  4. 点击应用
  5. 您现在将看到可以执行的所有批量编辑操作。选择 "comments" 下拉菜单,然后 select "Do not allow"
  6. 点击更新
  7. 如果使用缓存插件,请确保删除任何缓存

add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );

function woo_remove_product_tabs( $tabs ) {
    unset( $tabs['description'] );          // Remove the description tab
    unset( $tabs['reviews'] );          // Remove the reviews tab
    unset( $tabs['additional_information'] );   // Remove the additional information tab
    return $tabs;
}

function woocommerce_template_product_description() {
    woocommerce_get_template( 'single-product/tabs/description.php' );
}

add_action( 'woocommerce_after_single_product_summary',  'woocommerce_template_product_description', 40 );

这对我有用,因为我在这里得到了贡献。除了移除选项卡并将文本放回原处。

感谢 Swapnali 和 Mustafa

结合使用上述答案,将函数嵌套在操作中,以便您可以在条件中使用:

add_action( 'wp', 'custom_remove_tabs_by_tag' );
function custom_remove_tabs_by_tag() {
if ( is_product() && has_term( 'tag-term', 'product_tag' ) ) 
{    
    // Remove All Product Tabs
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
    // Add Product Description
    add_action( 'woocommerce_after_single_product_summary',
                 function () { woocommerce_get_template( 'single-product/tabs/description.php' );}, 
                 40 );
}