最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - How can I remove a WooCommerce Product Tab's sub section in wp-admin?

programmeradmin3浏览0评论

WooCommerce settings are located at wp-admin/admin.php?page=wc-settings and each of the Tabs for its settings is a continuation of the URL query string (ex: wp-admin/admin.php?page=wc-settings&tab=products for Products).

I know how to use the woocommerce_settings_tabs_array hook to manipulate the tab itself, but these Tabs also have sub links called "Sections."

For example, Products has General, Inventory, Downloadable Products and Product Vendors for me since I have a premium plugin.

How do I remove these sections from underneath the tab? Specifically, I want to remove the Product Vendors link that that premium extension added.

WooCommerce settings are located at wp-admin/admin.php?page=wc-settings and each of the Tabs for its settings is a continuation of the URL query string (ex: wp-admin/admin.php?page=wc-settings&tab=products for Products).

I know how to use the woocommerce_settings_tabs_array hook to manipulate the tab itself, but these Tabs also have sub links called "Sections."

For example, Products has General, Inventory, Downloadable Products and Product Vendors for me since I have a premium plugin.

How do I remove these sections from underneath the tab? Specifically, I want to remove the Product Vendors link that that premium extension added.

Share Improve this question asked Jun 16, 2018 at 1:07 user658182user658182 6252 gold badges14 silver badges35 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

To change this "sub navigation" you could use the WooCommerce filter "woocommerce_get_sections_products".

The following example code will remove the sub navigation point "inventory":

function change_navi_function($sections)
{
    // remove sub navigation point "inventory"
    unset($sections['inventory']);

    return $sections;
}

add_filter('woocommerce_get_sections_products', 'change_navi_function');

What you have to do now is either to hook your "change_navi_function" function after the function from the premium plugin and then remove the "Product Vendors" from the "$sections" array. Or you unhook the function from the premium plugin which use the "woocommerce_get_sections_products" filter.

you can find the file in ~/wp-content/plugins/woocommerce/includes/admin/views/html-admin-settings.php

foreach ( $tabs as $slug => $label ) {
    echo '<a href="' . esc_html( admin_url( 'admin.php?page=wc-settings&tab=' . esc_attr( $slug ) ) ) . '" class="nav-tab ' . ( $current_tab === $slug ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
}

and edit html-admin-settings.php add code

foreach ( $tabs as $slug => $label ) {
    if( $slug != "Product"){
        echo '<a href="' . esc_html( admin_url( 'admin.php?page=wc-settings&tab=' . esc_attr( $slug ) ) ) . '" class="nav-tab ' . ( $current_tab === $slug ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
    }   
}
发布评论

评论列表(0)

  1. 暂无评论