WooCommerce: Removing product write panel tab

2019-07-13 09:58发布

I’m using WooCommerce and I’d like to hide the "Linked Products" tab in the backend. I found a hook to add tabs (woocommerce_product_write_panel_tabs) but I’m not sure if it’s also possible to hide certain tabs with this hook.

Thanks for any help!

Product write panel tab

2条回答
该账号已被封号
2楼-- · 2019-07-13 10:20

So I had the same issue. Woocommerce provides a filter (just as they do about everything else) that can handle this. The filter is 'woocommerce_product_data_tabs'.

function remove_linked_products($tabs){
    unset($tabs['linked_product']);
    return($tabs);
}
add_filter('woocommerce_product_data_tabs', 'remove_linked_products', 10, 1);

This will remove the linked products tab. You can also unset the other tabs using their array index. Below is a copy of the filter application from class-wc-meta-box-product-data.php.

$product_data_tabs = apply_filters( 'woocommerce_product_data_tabs', array(
    'general' => array(
        'label'  => __( 'General', 'woocommerce' ),
        'target' => 'general_product_data',
        'class'  => array( 'hide_if_grouped' ),
    ),
    'inventory' => array(
        'label'  => __( 'Inventory', 'woocommerce' ),
        'target' => 'inventory_product_data',
        'class'  => array( 'show_if_simple', 'show_if_variable', 'show_if_grouped' ),
    ),
    'shipping' => array(
        'label'  => __( 'Shipping', 'woocommerce' ),
        'target' => 'shipping_product_data',
        'class'  => array( 'hide_if_virtual', 'hide_if_grouped', 'hide_if_external' ),
    ),
    'linked_product' => array(
        'label'  => __( 'Linked Products', 'woocommerce' ),
        'target' => 'linked_product_data',
        'class'  => array(),
    ),
    'attribute' => array(
        'label'  => __( 'Attributes', 'woocommerce' ),
        'target' => 'product_attributes',
        'class'  => array(),
    ),
    'variations' => array(
        'label'  => __( 'Variations', 'woocommerce' ),
        'target' => 'variable_product_options',
        'class'  => array( 'variations_tab', 'show_if_variable' ),
    ),
    'advanced' => array(
        'label'  => __( 'Advanced', 'woocommerce' ),
        'target' => 'advanced_product_data',
        'class'  => array(),
    )
));

So just substitute the unset($tabs['linked_product'] with whichever tab you want to remove from the backend.

查看更多
ら.Afraid
3楼-- · 2019-07-13 10:26

Adding the following to the wp-admin.min.css should remove the linked products.

li.linked_product_options.linked_product_tab
{
    display:none !important;
}
查看更多
登录 后发表回答