1

WooCommerce panel in Customizer

I have used the below code to remove other items from Customizer. But unable to remove the WooCommerce section.

function my_customize_register() {     
global $wp_customize;
$wp_customize->remove_section( 'colors' );
$wp_customize->remove_section( 'static_front_page' );
$wp_customize->remove_section( 'background_image' );
$wp_customize->remove_section( 'themes' ); 
$wp_customize->remove_section( 'header_image');
} 

add_action( 'customize_register', 'my_customize_register', 11 );



add_action('admin_menu', 'remove_unnecessary_wordpress_menus', 999);

function remove_unnecessary_wordpress_menus(){
    global $submenu;
    foreach($submenu['themes.php'] as $menu_index => $theme_menu){
        if($theme_menu[0] == 'Header' || $theme_menu[0] == 'Background')
        unset($submenu['themes.php'][$menu_index]);
    }
}
1
  • you try to edit /wp-admin/customize.php get this script document.getElementById( 'idwoocommerce' ).style.display = 'none'; Feb 8, 2018 at 20:43

2 Answers 2

2

WooCommerce adds itself to the customizer as a "panel", not a "section".

Add this to your my_customize_register() function and it will be gone:

$wp_customize->remove_panel( 'woocommerce' );

References:

As a rule of thumb, when you want to remove something (a customizer section, an action or filter, etc.) looking for how it is added in the first place is a good first step. More often than not it will point you in the right direction.
There are as many ways to remove things as there are to add them, and the right way to remove something often depends on how it was added.

4
  • You're welcome, glad I could help! Would you please accept the answer if it was helpful and answered your question?
    – Iceable
    Feb 9, 2018 at 6:33
  • Hi Iceable! I want to remove the 'Active Theme' section as well from Customizer. Any suggestion on how to do it? Thanks in anticipation. Feb 12, 2018 at 8:03
  • I'm not quite sure why you would want to remove this core section. If you are building a site for a client and want to declutter the admin to make it easier to manage for them, why don't you just give them an user access that doesn't have the 'switch_themes' capability; instead of removing admin menus and customizer sections? If you are building a theme to distribute and want to lock your users in by making it harder for them to switch themes, then this is a terrible idea which will only upset them.
    – Iceable
    Feb 12, 2018 at 9:37
  • I agree with you... Feb 12, 2018 at 10:36
1

Open admin page HTML source and find there all <li> elements having id attribute starting with accordion-section-. For example, for Homepage Settings it looks like:

<li id="accordion-section-static_front_page" class="accordion-section control-section control-section-default" aria-owns="sub-accordion-section-static_front_page" style="">

One of these <li> elements is WooCommerce-related, you'll see it. The last part of it's id (following the accordion-section- part) should be used in $wp_customize->remove_section().

1
  • Thanks Max. I used the id as you recommended, but it doesnt work! This is what i got <li id="accordion-panel-woocommerce" class="accordion-section control-section control-panel control-panel-default" aria-owns="sub-accordion-panel-woocommerce" style=""> Feb 8, 2018 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.