dongwolu5275 2019-08-09 14:03
浏览 195
已采纳

使用Avada删除特定产品的WooCommerce产品标签

Using WooCommerce 3.6.5 within the Avada theme.

We have one product with variations. The products with variation use WooCommerce Tabs in the presentation to give more information about the product. 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.]

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.

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.

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/

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', ? 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.

  • 写回答

1条回答 默认 最新

  • doujishan2247 2019-08-09 15:13
    关注

    First if you look to add_filter() function documentation, you will see that the third argument is related to the hook priority (in your case 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:

    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). It should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码