首页 > 解决方案 > 使用 Avada 删除特定产品的 WooCommerce 产品选项卡

问题描述

在 Avada 主题中使用 WooCommerce 3.6.5。

我们有一种产品有变化。具有变体的产品在演示文稿中使用 WooCommerce 选项卡来提供有关产品的更多信息。我需要保留这个。[我没有在我的 Wordpress/WooCommerce 管理面板中看到 WooCommerce 选项卡作为一个选项,我在很多视频中看到了如何更改或使用选项卡,或者任何看起来像他们管理这个的插件,所以我不知道如何标签正在处理中。]

我在网站上添加了一个新的简单产品,但该简单产品还从带有变体的产品中获取预先填充了与简单产品无关的信息的选项卡。

我通过使用 Firebug 来显示网页中 Div 的信息,将标签标识为属于 WooCommerce。

我需要防止标签显示在一个简单的产品上和/或更改标签的显示顺序或编号。很乐意在 PHP 代码中限制这一点。

发现此页面包含看似有用的信息以限制选项卡的显示 - https://docs.woocommerce.com/document/editing-product-data-tabs/

代码部分 -

/**
 * Remove product data tabs
 */
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;
}

困扰我的是这段代码的实现。

'woo_remove_product_tabs' 之后的“98”元素是什么?以及如何将这段代码限制为仅使用我拥有的一个简单产品,而不是所有产品和变体,或我将来可能添加的其他简单产品?

希望得到一些指导。

标签: phpwordpresswoocommercetabsproduct

解决方案


首先,如果您查看add_filter()函数文档,您会看到第三个参数与钩子优先级相关(在您的情况下为 98)......</p>

要仅针对简单产品,您将使用该WC_Product is_type()方法,并在下面的代码中定义所需的产品 ID:

add_filter( 'woocommerce_product_tabs', 'removing_product_tabs', 98 );
function removing_product_tabs( $tabs ) {
    // Get the global product object
    global $product;

    // HERE define your specific product Ids
    $targeted_ids = array( 37, 56, 63 );

    if( $product->is_type( 'simple' ) && in_array( $product->get_id(), $targeted_ids ) ) {
        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;
}

代码在您的活动子主题(活动活动主题)的functions.php 文件中。它应该工作。


推荐阅读