简体   繁体   English

使用 Avada 删除特定产品的 WooCommerce 产品选项卡

[英]Remove WooCommerce product tabs for specific products with Avada

Using WooCommerce 3.6.5 within the Avada theme.在 Avada 主题中使用 WooCommerce 3.6.5。

We have one product with variations.我们有一种有变化的产品。 The products with variation use WooCommerce Tabs in the presentation to give more information about the product.有变化的产品在演示文稿中使用 WooCommerce 选项卡来提供有关产品的更多信息。 I need to retain this.我需要保留这个。 [I do not see WooCommerce Tabs as an option within my Wordpress/WooCommerce admin panel that I see on so many videos detailing how to change or use Tabs, or any plugin that looks like they manage this, so I am at a loss to how the tabs are being handled.] [我在 Wordpress/WooCommerce 管理面板中没有看到 WooCommerce 选项卡作为选项,我在很多详细介绍如何更改或使用选项卡的视频或任何看起来像他们管理此功能的插件中看到,所以我不知道如何正在处理选项卡。]

I have a new simple product added to the site, but the simple product also gets the tabs prepopulated with information that is not relevant to the simple product, from the product with variations.我向站点添加了一个新的简单产品,但简单产品还从带有变体的产品中获取预先填充了与简单产品无关的信息的选项卡。

I have identified the Tabs as belonging to WooCommerce through using Firebug to reveal information on the Divs within the webpage.我通过使用 Firebug 显示网页中 Div 的信息,将这些标签确定为属于 WooCommerce。

I need to prevent the tabs being displayed on the one simple product and/or change the tabs presentation order, or number.我需要防止在一个简单的产品上显示选项卡和/或更改选项卡的显示顺序或编号。 Would be happy to limit this within PHP code.很乐意将其限制在 PHP 代码中。

Have found this page with what looks like useful information to limit the presentation of tabs - https://docs.woocommerce.com/document/editing-product-data-tabs/找到了这个页面,其中包含限制选项卡显示的有用信息 - https://docs.woocommerce.com/document/editing-product-data-tabs/

Section of code -代码部分 -

/**
 * 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;
}

What bothers me is the implementation of this code.困扰我的是这段代码的实现。

What is the "98" element after 'woo_remove_product_tabs', ? 'woo_remove_product_tabs' 后面的“98”元素是什么? and how can I limit this bit of code to only operate with the one simple product I have, rather than all the products and variations, or other simple products I may add in the future ?以及如何将这段代码限制为仅适用于我拥有的一个简单产品,而不是所有产品和变体,或者我将来可能添加的其他简单产品?

Would appreciate some guidance.希望得到一些指导。

First if you look toadd_filter() function documentation , you will see that the third argument is related to the hook priority (in your case 98)…首先,如果您查看add_filter()函数文档,您会看到第三个参数与钩子优先级有关(在您的情况下为 98)...

To target simple products only you will use the WC_Product is_type() method and you will define your desired product Ids in the code below:要仅定位简单产品,您将使用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;
}

Code goes in functions.php file of your active child theme (active active theme).代码位于您的活动子主题(活动活动主题)的 functions.php 文件中。 It should work.它应该工作。

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

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